From ae100e0e8273b09dd1c2f2ee08388440c2662fad Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 16 Sep 2018 01:17:06 +0200 Subject: commands: add a title edit command --- commands/title.go | 2 +- commands/title_edit.go | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 commands/title_edit.go (limited to 'commands') diff --git a/commands/title.go b/commands/title.go index 70355986..16cfc342 100644 --- a/commands/title.go +++ b/commands/title.go @@ -48,5 +48,5 @@ var titleCmd = &cobra.Command{ func init() { RootCmd.AddCommand(titleCmd) - commentCmd.Flags().SortFlags = false + titleCmd.Flags().SortFlags = false } diff --git a/commands/title_edit.go b/commands/title_edit.go new file mode 100644 index 00000000..111c6325 --- /dev/null +++ b/commands/title_edit.go @@ -0,0 +1,75 @@ +package commands + +import ( + "errors" + "fmt" + + "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/input" + "github.com/spf13/cobra" +) + +var ( + titleEditTitle string +) + +func runTitleEdit(cmd *cobra.Command, args []string) error { + var err error + + if len(args) > 1 { + return errors.New("Only one bug id is supported") + } + + if len(args) == 0 { + return errors.New("You must provide a bug id") + } + + backend, err := cache.NewRepoCache(repo) + if err != nil { + return err + } + defer backend.Close() + + prefix := args[0] + + b, err := backend.ResolveBugPrefix(prefix) + if err != nil { + return err + } + + snap := b.Snapshot() + + if titleEditTitle == "" { + titleEditTitle, err = input.BugTitleEditorInput(repo, snap.Title) + if err == input.ErrEmptyTitle { + fmt.Println("Empty title, aborting.") + return nil + } + if err != nil { + return err + } + } + + err = b.SetTitle(titleEditTitle) + if err != nil { + return err + } + + return b.Commit() +} + +var titleEditCmd = &cobra.Command{ + Use: "edit ", + Short: "Edit a bug title", + RunE: runTitleEdit, +} + +func init() { + titleCmd.AddCommand(titleEditCmd) + + titleEditCmd.Flags().SortFlags = false + + titleEditCmd.Flags().StringVarP(&titleEditTitle, "title", "t", "", + "Provide a title to describe the issue", + ) +} -- cgit