From d9f7269507cfc65a2fec05651bdff00978e0d1ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sun, 16 Sep 2018 01:04:29 +0200 Subject: [PATCH] commands: add a title command to display a bug's title --- commands/title.go | 52 ++++++++++++++++++++++++++++++++++++ doc/man/git-bug-title.1 | 29 ++++++++++++++++++++ doc/man/git-bug.1 | 2 +- doc/md/git-bug.md | 1 + doc/md/git-bug_title.md | 22 +++++++++++++++ misc/bash_completion/git-bug | 21 +++++++++++++++ misc/zsh_completion/git-bug | 2 +- 7 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 commands/title.go create mode 100644 doc/man/git-bug-title.1 create mode 100644 doc/md/git-bug_title.md 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 +} diff --git a/doc/man/git-bug-title.1 b/doc/man/git-bug-title.1 new file mode 100644 index 00000000..3d6adc43 --- /dev/null +++ b/doc/man/git-bug-title.1 @@ -0,0 +1,29 @@ +.TH "GIT-BUG" "1" "Sep 2018" "Generated from git-bug's source code" "" +.nh +.ad l + + +.SH NAME +.PP +git\-bug\-title \- Show a bug's title + + +.SH SYNOPSIS +.PP +\fBgit\-bug title [flags]\fP + + +.SH DESCRIPTION +.PP +Show a bug's title + + +.SH OPTIONS +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for title + + +.SH SEE ALSO +.PP +\fBgit\-bug(1)\fP diff --git a/doc/man/git-bug.1 b/doc/man/git-bug.1 index 9d370dc8..514dc093 100644 --- a/doc/man/git-bug.1 +++ b/doc/man/git-bug.1 @@ -29,4 +29,4 @@ It use the same internal storage so it doesn't pollute your project. As you woul .SH SEE ALSO .PP -\fBgit\-bug\-add(1)\fP, \fBgit\-bug\-close(1)\fP, \fBgit\-bug\-commands(1)\fP, \fBgit\-bug\-comment(1)\fP, \fBgit\-bug\-label(1)\fP, \fBgit\-bug\-ls(1)\fP, \fBgit\-bug\-open(1)\fP, \fBgit\-bug\-pull(1)\fP, \fBgit\-bug\-push(1)\fP, \fBgit\-bug\-show(1)\fP, \fBgit\-bug\-termui(1)\fP, \fBgit\-bug\-webui(1)\fP +\fBgit\-bug\-add(1)\fP, \fBgit\-bug\-close(1)\fP, \fBgit\-bug\-commands(1)\fP, \fBgit\-bug\-comment(1)\fP, \fBgit\-bug\-label(1)\fP, \fBgit\-bug\-ls(1)\fP, \fBgit\-bug\-open(1)\fP, \fBgit\-bug\-pull(1)\fP, \fBgit\-bug\-push(1)\fP, \fBgit\-bug\-show(1)\fP, \fBgit\-bug\-termui(1)\fP, \fBgit\-bug\-title(1)\fP, \fBgit\-bug\-webui(1)\fP diff --git a/doc/md/git-bug.md b/doc/md/git-bug.md index b3f66627..c99afe7e 100644 --- a/doc/md/git-bug.md +++ b/doc/md/git-bug.md @@ -31,5 +31,6 @@ git-bug [flags] * [git-bug push](git-bug_push.md) - Push bugs update to a git remote * [git-bug show](git-bug_show.md) - Display the details of a bug * [git-bug termui](git-bug_termui.md) - Launch the terminal UI +* [git-bug title](git-bug_title.md) - Show a bug's title * [git-bug webui](git-bug_webui.md) - Launch the web UI diff --git a/doc/md/git-bug_title.md b/doc/md/git-bug_title.md new file mode 100644 index 00000000..c3a633dd --- /dev/null +++ b/doc/md/git-bug_title.md @@ -0,0 +1,22 @@ +## git-bug title + +Show a bug's title + +### Synopsis + +Show a bug's title + +``` +git-bug title [flags] +``` + +### Options + +``` + -h, --help help for title +``` + +### SEE ALSO + +* [git-bug](git-bug.md) - A bugtracker embedded in Git + diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 9fb336b4..36da665c 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -528,6 +528,26 @@ _git-bug_termui() noun_aliases=() } +_git-bug_title() +{ + last_command="git-bug_title" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + _git-bug_webui() { last_command="git-bug_webui" @@ -569,6 +589,7 @@ _git-bug_root_command() commands+=("push") commands+=("show") commands+=("termui") + commands+=("title") commands+=("webui") flags=() diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index 4f1b4dd2..31dd5ee0 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -8,7 +8,7 @@ case $state in level1) case $words[1] in git-bug) - _arguments '1: :(add close commands comment label ls open pull push show termui webui)' + _arguments '1: :(add close commands comment label ls open pull push show termui title webui)' ;; *) _arguments '*: :_files'