github.com/driusan/bug@v0.3.2-0.20190306121946-d7f4e7f33fea/main.go (about)

     1  // bug writes code problem reports to plain text files.
     2  package main
     3  
     4  import (
     5  	"fmt"
     6  	"github.com/driusan/bug/bugapp"
     7  	"github.com/driusan/bug/bugs"
     8  	"os"
     9  )
    10  
    11  func main() {
    12  	var skipRootCheck bool = false
    13  	switch len(os.Args) {
    14  	case 0, 1:
    15  		skipRootCheck = true
    16  	case 2:
    17  		if os.Args[1] == "help" {
    18  			skipRootCheck = true
    19  		}
    20  	case 3:
    21  		if os.Args[2] == "--help" {
    22  			skipRootCheck = true
    23  		}
    24  
    25  	}
    26  	if skipRootCheck == false && bugs.GetRootDir() == "" {
    27  		fmt.Printf("Could not find issues directory.\n")
    28  		fmt.Printf("Make sure either the PMIT environment variable is set, or a parent directory of your working directory has an issues folder.\n")
    29  		fmt.Println("(If you just started new repo, you probably want to create directory named `issues`).")
    30  		fmt.Printf("Aborting.\n")
    31  		os.Exit(2)
    32  
    33  	}
    34  
    35  	if len(os.Args) > 1 {
    36  		if len(os.Args) >= 3 && os.Args[2] == "--help" {
    37  			os.Args[1], os.Args[2] = "help", os.Args[1]
    38  		}
    39  		switch os.Args[1] {
    40  		case "add", "new", "create":
    41  			bugapp.Create(os.Args[2:])
    42  		case "view", "list":
    43  			// bug list with no parameters shouldn't autopage,
    44  			// bug list with bugs to view should. So the original
    45  			// stdout is passed as a parameter.
    46  			bugapp.List(os.Args[2:])
    47  		case "priority":
    48  			bugapp.Priority(os.Args[2:])
    49  		case "status":
    50  			bugapp.Status(os.Args[2:])
    51  		case "milestone":
    52  			bugapp.Milestone(os.Args[2:])
    53  		case "id", "identifier":
    54  			bugapp.Identifier(os.Args[2:])
    55  		case "tag":
    56  			bugapp.Tag(os.Args[2:])
    57  		case "mv", "rename", "retitle", "relabel":
    58  			bugapp.Relabel(os.Args[2:])
    59  		case "purge":
    60  			bugapp.Purge()
    61  		case "rm", "close":
    62  			bugapp.Close(os.Args[2:])
    63  		case "edit":
    64  			bugapp.Edit(os.Args[2:])
    65  		case "--version", "version":
    66  			bugapp.Version()
    67  		case "env":
    68  			bugapp.Env()
    69  		case "dir", "pwd":
    70  			bugapp.Pwd()
    71  		case "commit":
    72  			bugapp.Commit(os.Args[2:])
    73  		case "roadmap":
    74  			bugapp.Roadmap(os.Args[2:])
    75  		case "find":
    76  			bugapp.Find(os.Args[2:])
    77  		case "help":
    78  			fallthrough
    79  		default:
    80  			bugapp.Help(os.Args[1:]...)
    81  		}
    82  	} else {
    83  		bugapp.Help()
    84  	}
    85  }