From 6cdc6c087e858e18c5c54e92c60ceb78a37fc3f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Mur=C3=A9?= Date: Sat, 15 Sep 2018 20:31:40 +0200 Subject: [PATCH] commands: add `git bug comment add` to add a comment --- commands/comment_add.go | 85 +++++++++++++++++++++++++++++++++++ doc/man/git-bug-add.1 | 41 +++++++++++++++++ doc/man/git-bug-comment-add.1 | 29 ++++++++++++ doc/man/git-bug-comment.1 | 6 +-- doc/man/git-bug.1 | 2 +- doc/md/git-bug.md | 4 +- doc/md/git-bug_add.md | 25 +++++++++++ doc/md/git-bug_comment.md | 5 ++- doc/md/git-bug_comment_add.md | 22 +++++++++ misc/bash_completion/git-bug | 81 ++++++++++++++++++++------------- misc/zsh_completion/git-bug | 15 ++++++- 11 files changed, 275 insertions(+), 40 deletions(-) create mode 100644 commands/comment_add.go create mode 100644 doc/man/git-bug-add.1 create mode 100644 doc/man/git-bug-comment-add.1 create mode 100644 doc/md/git-bug_add.md create mode 100644 doc/md/git-bug_comment_add.md diff --git a/commands/comment_add.go b/commands/comment_add.go new file mode 100644 index 00000000..46d0c8b8 --- /dev/null +++ b/commands/comment_add.go @@ -0,0 +1,85 @@ +package commands + +import ( + "fmt" + + "github.com/MichaelMure/git-bug/cache" + "github.com/MichaelMure/git-bug/input" + "github.com/pkg/errors" + "github.com/spf13/cobra" +) + +var ( + commentAddMessageFile string + commentAddMessage string +) + +func runCommentAdd(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] + + if commentAddMessageFile != "" && commentAddMessage == "" { + commentAddMessage, err = input.FromFile(commentAddMessageFile) + if err != nil { + return err + } + } + + if commentAddMessage == "" { + commentAddMessage, err = input.BugCommentEditorInput(backend.Repository()) + if err == input.ErrEmptyMessage { + fmt.Println("Empty message, aborting.") + return nil + } + if err != nil { + return err + } + } + + b, err := backend.ResolveBugPrefix(prefix) + if err != nil { + return err + } + + err = b.AddComment(commentAddMessage) + if err != nil { + return err + } + + return b.Commit() +} + +var commentAddCmd = &cobra.Command{ + Use: "add ", + Short: "Add a new comment to a bug", + RunE: runCommentAdd, +} + +func init() { + commentCmd.AddCommand(commentAddCmd) + + commentCmd.Flags().SortFlags = false + + commentCmd.Flags().StringVarP(&commentAddMessageFile, "file", "F", "", + "Take the message from the given file. Use - to read the message from the standard input", + ) + + commentCmd.Flags().StringVarP(&commentAddMessage, "message", "m", "", + "Provide the new message from the command line", + ) +} diff --git a/doc/man/git-bug-add.1 b/doc/man/git-bug-add.1 new file mode 100644 index 00000000..cc486564 --- /dev/null +++ b/doc/man/git-bug-add.1 @@ -0,0 +1,41 @@ +.TH "GIT-BUG" "1" "Sep 2018" "Generated from git-bug's source code" "" +.nh +.ad l + + +.SH NAME +.PP +git\-bug\-add \- Create a new bug + + +.SH SYNOPSIS +.PP +\fBgit\-bug add [flags]\fP + + +.SH DESCRIPTION +.PP +Create a new bug + + +.SH OPTIONS +.PP +\fB\-t\fP, \fB\-\-title\fP="" + Provide a title to describe the issue + +.PP +\fB\-m\fP, \fB\-\-message\fP="" + Provide a message to describe the issue + +.PP +\fB\-F\fP, \fB\-\-file\fP="" + Take the message from the given file. Use \- to read the message from the standard input + +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for add + + +.SH SEE ALSO +.PP +\fBgit\-bug(1)\fP diff --git a/doc/man/git-bug-comment-add.1 b/doc/man/git-bug-comment-add.1 new file mode 100644 index 00000000..1a2fc2dc --- /dev/null +++ b/doc/man/git-bug-comment-add.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\-comment\-add \- Add a new comment to a bug + + +.SH SYNOPSIS +.PP +\fBgit\-bug comment add [flags]\fP + + +.SH DESCRIPTION +.PP +Add a new comment to a bug + + +.SH OPTIONS +.PP +\fB\-h\fP, \fB\-\-help\fP[=false] + help for add + + +.SH SEE ALSO +.PP +\fBgit\-bug\-comment(1)\fP diff --git a/doc/man/git-bug-comment.1 b/doc/man/git-bug-comment.1 index 7e172d6b..8ad43e5c 100644 --- a/doc/man/git-bug-comment.1 +++ b/doc/man/git-bug-comment.1 @@ -5,7 +5,7 @@ .SH NAME .PP -git\-bug\-comment \- Add a new comment to a bug +git\-bug\-comment \- Show a bug's comments .SH SYNOPSIS @@ -15,7 +15,7 @@ git\-bug\-comment \- Add a new comment to a bug .SH DESCRIPTION .PP -Add a new comment to a bug +Show a bug's comments .SH OPTIONS @@ -34,4 +34,4 @@ Add a new comment to a bug .SH SEE ALSO .PP -\fBgit\-bug(1)\fP +\fBgit\-bug(1)\fP, \fBgit\-bug\-comment\-add(1)\fP diff --git a/doc/man/git-bug.1 b/doc/man/git-bug.1 index 21f012b2..9d370dc8 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\-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\-new(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\-webui(1)\fP diff --git a/doc/md/git-bug.md b/doc/md/git-bug.md index 6131ed2c..b3f66627 100644 --- a/doc/md/git-bug.md +++ b/doc/md/git-bug.md @@ -20,12 +20,12 @@ git-bug [flags] ### SEE ALSO +* [git-bug add](git-bug_add.md) - Create a new bug * [git-bug close](git-bug_close.md) - Mark the bug as closed * [git-bug commands](git-bug_commands.md) - Display available commands -* [git-bug comment](git-bug_comment.md) - Add a new comment to a bug +* [git-bug comment](git-bug_comment.md) - Show a bug's comments * [git-bug label](git-bug_label.md) - Manipulate bug's label * [git-bug ls](git-bug_ls.md) - List bugs -* [git-bug new](git-bug_new.md) - Create a new bug * [git-bug open](git-bug_open.md) - Mark the bug as open * [git-bug pull](git-bug_pull.md) - Pull bugs update from a git remote * [git-bug push](git-bug_push.md) - Push bugs update to a git remote diff --git a/doc/md/git-bug_add.md b/doc/md/git-bug_add.md new file mode 100644 index 00000000..21060f61 --- /dev/null +++ b/doc/md/git-bug_add.md @@ -0,0 +1,25 @@ +## git-bug add + +Create a new bug + +### Synopsis + +Create a new bug + +``` +git-bug add [flags] +``` + +### Options + +``` + -t, --title string Provide a title to describe the issue + -m, --message string Provide a message to describe the issue + -F, --file string Take the message from the given file. Use - to read the message from the standard input + -h, --help help for add +``` + +### SEE ALSO + +* [git-bug](git-bug.md) - A bugtracker embedded in Git + diff --git a/doc/md/git-bug_comment.md b/doc/md/git-bug_comment.md index 8616c511..9870e5fe 100644 --- a/doc/md/git-bug_comment.md +++ b/doc/md/git-bug_comment.md @@ -1,10 +1,10 @@ ## git-bug comment -Add a new comment to a bug +Show a bug's comments ### Synopsis -Add a new comment to a bug +Show a bug's comments ``` git-bug comment [flags] @@ -21,4 +21,5 @@ git-bug comment [flags] ### SEE ALSO * [git-bug](git-bug.md) - A bugtracker embedded in Git +* [git-bug comment add](git-bug_comment_add.md) - Add a new comment to a bug diff --git a/doc/md/git-bug_comment_add.md b/doc/md/git-bug_comment_add.md new file mode 100644 index 00000000..412e40d7 --- /dev/null +++ b/doc/md/git-bug_comment_add.md @@ -0,0 +1,22 @@ +## git-bug comment add + +Add a new comment to a bug + +### Synopsis + +Add a new comment to a bug + +``` +git-bug comment add [flags] +``` + +### Options + +``` + -h, --help help for add +``` + +### SEE ALSO + +* [git-bug comment](git-bug_comment.md) - Show a bug's comments + diff --git a/misc/bash_completion/git-bug b/misc/bash_completion/git-bug index 94c2db96..9fb336b4 100644 --- a/misc/bash_completion/git-bug +++ b/misc/bash_completion/git-bug @@ -248,6 +248,35 @@ _git_bug() { __start_git-bug "$@" } +_git-bug_add() +{ + last_command="git-bug_add" + + command_aliases=() + + commands=() + + flags=() + two_word_flags=() + local_nonpersistent_flags=() + flags_with_completion=() + flags_completion=() + + flags+=("--title=") + two_word_flags+=("-t") + local_nonpersistent_flags+=("--title=") + flags+=("--message=") + two_word_flags+=("-m") + local_nonpersistent_flags+=("--message=") + flags+=("--file=") + two_word_flags+=("-F") + local_nonpersistent_flags+=("--file=") + + must_have_one_flag=() + must_have_one_noun=() + noun_aliases=() +} + _git-bug_close() { last_command="git-bug_close" @@ -291,6 +320,26 @@ _git-bug_commands() noun_aliases=() } +_git-bug_comment_add() +{ + last_command="git-bug_comment_add" + + 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_comment() { last_command="git-bug_comment" @@ -298,6 +347,7 @@ _git-bug_comment() command_aliases=() commands=() + commands+=("add") flags=() two_word_flags=() @@ -378,35 +428,6 @@ _git-bug_ls() noun_aliases=() } -_git-bug_new() -{ - last_command="git-bug_new" - - command_aliases=() - - commands=() - - flags=() - two_word_flags=() - local_nonpersistent_flags=() - flags_with_completion=() - flags_completion=() - - flags+=("--title=") - two_word_flags+=("-t") - local_nonpersistent_flags+=("--title=") - flags+=("--message=") - two_word_flags+=("-m") - local_nonpersistent_flags+=("--message=") - flags+=("--file=") - two_word_flags+=("-F") - local_nonpersistent_flags+=("--file=") - - must_have_one_flag=() - must_have_one_noun=() - noun_aliases=() -} - _git-bug_open() { last_command="git-bug_open" @@ -537,12 +558,12 @@ _git-bug_root_command() command_aliases=() commands=() + commands+=("add") commands+=("close") commands+=("commands") commands+=("comment") commands+=("label") commands+=("ls") - commands+=("new") commands+=("open") commands+=("pull") commands+=("push") diff --git a/misc/zsh_completion/git-bug b/misc/zsh_completion/git-bug index dcd83163..4f1b4dd2 100644 --- a/misc/zsh_completion/git-bug +++ b/misc/zsh_completion/git-bug @@ -2,12 +2,23 @@ _arguments \ '1: :->level1' \ - '2: :_files' + '2: :->level2' \ + '3: :_files' case $state in level1) case $words[1] in git-bug) - _arguments '1: :(close commands comment label ls new open pull push show termui webui)' + _arguments '1: :(add close commands comment label ls open pull push show termui webui)' + ;; + *) + _arguments '*: :_files' + ;; + esac + ;; + level2) + case $words[2] in + comment) + _arguments '2: :(add)' ;; *) _arguments '*: :_files'