2018-09-16 14:50:53 +03:00
|
|
|
// Package commands contains the CLI commands
|
2018-07-19 13:30:25 +03:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2018-08-13 19:32:11 +03:00
|
|
|
"os"
|
|
|
|
|
2019-09-06 12:01:09 +03:00
|
|
|
"github.com/spf13/cobra"
|
2018-07-19 13:30:25 +03:00
|
|
|
)
|
|
|
|
|
2018-07-20 16:46:14 +03:00
|
|
|
const rootCommandName = "git-bug"
|
2018-07-19 13:30:25 +03:00
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
// These variables are initialized externally during the build. See the Makefile.
|
|
|
|
var GitCommit string
|
|
|
|
var GitLastTag string
|
|
|
|
var GitExactTag string
|
2018-07-19 13:30:25 +03:00
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
func NewRootCommand() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: rootCommandName,
|
|
|
|
Short: "A bug tracker embedded in Git.",
|
|
|
|
Long: `git-bug is a bug tracker embedded in git.
|
2018-07-19 13:30:25 +03:00
|
|
|
|
2018-10-17 21:47:31 +03:00
|
|
|
git-bug use git objects to store the bug tracking separated from the files
|
2018-10-17 21:05:32 +03:00
|
|
|
history. As bugs are regular git objects, they can be pushed and pulled from/to
|
2020-04-30 23:24:03 +03:00
|
|
|
the same git remote you are already using to collaborate with other people.
|
2018-10-17 21:05:32 +03:00
|
|
|
|
|
|
|
`,
|
2018-07-19 13:30:25 +03:00
|
|
|
|
2020-06-28 19:26:29 +03:00
|
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
|
|
|
root := cmd.Root()
|
|
|
|
|
|
|
|
if GitExactTag == "undefined" {
|
|
|
|
GitExactTag = ""
|
|
|
|
}
|
|
|
|
root.Version = GitLastTag
|
|
|
|
if GitExactTag == "" {
|
|
|
|
root.Version = fmt.Sprintf("%s-dev-%.10s", root.Version, GitCommit)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
// For the root command, force the execution of the PreRun
|
|
|
|
// even if we just display the help. This is to make sure that we check
|
|
|
|
// the repository and give the user early feedback.
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
|
|
if err := cmd.Help(); err != nil {
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
SilenceUsage: true,
|
|
|
|
DisableAutoGenTag: true,
|
|
|
|
|
|
|
|
// Custom bash code to connect the git completion for "git bug" to the
|
|
|
|
// git-bug completion for "git-bug"
|
|
|
|
BashCompletionFunction: `
|
2018-08-08 21:12:04 +03:00
|
|
|
_git_bug() {
|
|
|
|
__start_git-bug "$@"
|
|
|
|
}
|
|
|
|
`,
|
2020-06-28 19:26:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd.AddCommand(newAddCommand())
|
|
|
|
cmd.AddCommand(newBridgeCommand())
|
|
|
|
cmd.AddCommand(newCommandsCommand())
|
|
|
|
cmd.AddCommand(newCommentCommand())
|
|
|
|
cmd.AddCommand(newDeselectCommand())
|
|
|
|
cmd.AddCommand(newLabelCommand())
|
|
|
|
cmd.AddCommand(newLsCommand())
|
|
|
|
cmd.AddCommand(newLsIdCommand())
|
|
|
|
cmd.AddCommand(newLsLabelCommand())
|
|
|
|
cmd.AddCommand(newPullCommand())
|
|
|
|
cmd.AddCommand(newPushCommand())
|
2020-07-16 12:12:48 +03:00
|
|
|
cmd.AddCommand(newRmCommand())
|
2020-06-28 19:26:29 +03:00
|
|
|
cmd.AddCommand(newSelectCommand())
|
|
|
|
cmd.AddCommand(newShowCommand())
|
|
|
|
cmd.AddCommand(newStatusCommand())
|
|
|
|
cmd.AddCommand(newTermUICommand())
|
|
|
|
cmd.AddCommand(newTitleCommand())
|
|
|
|
cmd.AddCommand(newUserCommand())
|
|
|
|
cmd.AddCommand(newVersionCommand())
|
|
|
|
cmd.AddCommand(newWebUICommand())
|
|
|
|
|
|
|
|
return cmd
|
2018-07-19 13:30:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func Execute() {
|
2020-06-28 19:26:29 +03:00
|
|
|
if err := NewRootCommand().Execute(); err != nil {
|
2018-07-19 13:30:25 +03:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|