From d9f7269507cfc65a2fec05651bdff00978e0d1ec Mon Sep 17 00:00:00 2001 From: Michael Muré Date: Sun, 16 Sep 2018 01:04:29 +0200 Subject: commands: add a title command to display a bug's title --- commands/title.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 commands/title.go (limited to 'commands') diff --git a/commands/title.go b/commands/title.go new file mode 100644 index 00000000..70355986 --- /dev/null +++ b/commands/title.go @@ -0,0 +1,52 @@ +package commands + +import ( + "fmt" + + "github.com/MichaelMure/git-bug/cache" + "github.com/pkg/errors" + "github.com/spf13/cobra" +) + +func runTitle(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() + + fmt.Println(snap.Title) + + return nil +} + +var titleCmd = &cobra.Command{ + Use: "title ", + Short: "Display a bug's title", + RunE: runTitle, +} + +func init() { + RootCmd.AddCommand(titleCmd) + + commentCmd.Flags().SortFlags = false +} -- cgit