github.com/grantbow/fit@v0.7.1-0.20220916164603-1f7c88ac81e6/fitapp/Close.go (about) 1 package fitapp 2 3 import ( 4 "fmt" 5 bugs "github.com/grantbow/fit/issues" 6 "os" 7 ) 8 9 // Close is a subcommand to close issues. 10 func Close(args argumentList, config bugs.Config) { 11 // No parameters, print a list of all bugs 12 if len(args) == 0 { 13 fmt.Fprintf(os.Stderr, "Usage: %s close <IssueID>\n\nMust provide an ID to close as parameter\n", os.Args[0]) 14 return 15 } 16 17 // There were parameters, so show the full description of each 18 // of those issues 19 var bugsToClose []string 20 for _, bugID := range args { 21 if bug, err := bugs.LoadIssueByHeuristic(bugID, config); err == nil { 22 dir := bug.Direr() 23 bugsToClose = append(bugsToClose, string(dir)) 24 if config.CloseStatusTag { 25 fmt.Printf("Tag status closed %s\n", dir) 26 err = bug.SetField("Status", "closed", config) 27 if err != nil { 28 fmt.Fprintf(os.Stderr, "Error setting %s %s : %s\n", "Status", "closed", err.Error()) 29 } 30 } 31 } else { 32 fmt.Fprintf(os.Stderr, "Could not close issue %s: %s\n", bugID, err.Error()) 33 } 34 } 35 for _, dir := range bugsToClose { 36 if config.CloseMove { 37 fmt.Printf("Moving %s to %s\n", dir, config.ClosedDirName) 38 err := os.Rename(dir, config.ClosedDirName+sops+dir) 39 if err != nil { 40 fmt.Fprintf(os.Stderr, "Error renaming %s : %s\n", dir, err.Error()) 41 } 42 } else if !config.ClosePreventDelete { 43 fmt.Printf("Removing %s\n", dir) 44 err := os.RemoveAll(dir) 45 if err != nil { 46 fmt.Fprintf(os.Stderr, "Error removing %s : %s\n", dir, err.Error()) 47 } 48 } 49 } 50 }