func edit(c *cli.Context) { cfg, err := common.TenetCfgPath(c) if err != nil { fmt.Println(err) return } cmd, err := util.OpenFileCmd(c.String("editor"), cfg, 0) if err != nil { fmt.Println(err) return } cmd.Run() }
// Edit assumes cfgFilename is relative to $LINGO_HOME and opens that // file with the provided editor. func Edit(cfgFilename, editor string) error { cfgPath, err := fullCfgPath(cfgFilename) if err != nil { return errors.Trace(err) } cmd, err := util.OpenFileCmd(editor, cfgPath, 0) if err != nil { return errors.Trace(err) } if err = cmd.Start(); err != nil { return errors.Trace(err) } if err = cmd.Wait(); err != nil { return errors.Trace(err) } return nil }
// confirm returns true if the issue should be kept or false if it should be // dropped. func (c IssueConfirmer) Confirm(attempt int, issue *tenet.Issue) bool { if c.keepAll { return true } if attempt == 0 { fmt.Println(c.FormatPlainText(issue)) } attempt++ var options string fmt.Print("\n[o]pen") if c.output { fmt.Print(" [d]iscard [K]eep") } fmt.Print(": ") fmt.Scanln(&options) // if err != nil || n != 1 { // // TODO(waigani) handle invalid input // fmt.Println("invalid input", n, err) // } switch options { case "o": var app string defaultEditor := "vi" // TODO(waigani) is vi an okay default? if editor != "" { defaultEditor = editor } fmt.Printf("application (%s):", defaultEditor) fmt.Scanln(&app) filename := issue.Position.Start.Filename if app == "" { app = defaultEditor } // c := issue.Position.Start.Column // TODO(waigani) use column l := issue.Position.Start.Line cmd, err := util.OpenFileCmd(app, filename, l) if err != nil { fmt.Println(err) return c.Confirm(attempt, issue) } if err = cmd.Start(); err != nil { log.Println(err) } if err = cmd.Wait(); err != nil { log.Println(err) } editor = app c.Confirm(attempt, issue) case "d": issue.Discard = true // TODO(waigani) only prompt for reason if we're sending to a service. fmt.Print("reason: ") in := bufio.NewReader(os.Stdin) issue.DiscardReason, _ = in.ReadString('\n') // TODO(waigani) we are now always returning true. Returning a bool at // all doesn't make sense and KeptIssues in commands/common.go should // be renamed to "AllIssues" or the like. return true case "", "k", "K", "\n": return true default: fmt.Printf("invalid input: %s\n", options) fmt.Println(options) c.Confirm(attempt, issue) } return true }
// confirm returns true if the issue should be kept or false if it should be // dropped. func (c IssueConfirmer) Confirm(attempt int, issue *api.Issue) bool { if attempt == 0 { if c.inDiff != nil && !c.inDiff(issue) { return false } if !c.userConfirm { return true } } if attempt == 0 { fmt.Println(c.FormatPlainText(issue)) } attempt++ var options string fmt.Print("\n[o]pen") if c.output { fmt.Print(" [d]iscard [K]eep") } fmt.Print(": ") fmt.Scanln(&options) // if err != nil || n != 1 { // // TODO(waigani) handle invalid input // fmt.Println("invalid input", n, err) // } switch options { case "o": var app string defaultEditor := "vi" // TODO(waigani) is vi an okay default? if editor != "" { defaultEditor = editor } fmt.Printf("application (%s):", defaultEditor) fmt.Scanln(&app) filename := c.hostFilePath(issue.Position.Start.Filename) if app == "" { app = defaultEditor } // c := issue.Position.Start.Column // TODO(waigani) use column l := issue.Position.Start.Line cmd, err := util.OpenFileCmd(app, filename, l) if err != nil { fmt.Println(err) } if err = cmd.Start(); err != nil { log.Println(err) } if err = cmd.Wait(); err != nil { log.Println(err) } editor = app c.Confirm(attempt, issue) case "d": return false case "", "k", "K", "\n": return true default: fmt.Printf("invalid input: %s\n", options) fmt.Println(options) c.Confirm(attempt, issue) } return true }