commands: don't load the repo for commands that don't need it

Michael Muré created

fix #67

Change summary

commands/add.go              | 7 ++++---
commands/bridge.go           | 9 +++++----
commands/bridge_configure.go | 7 ++++---
commands/bridge_pull.go      | 7 ++++---
commands/bridge_rm.go        | 9 +++++----
commands/comment.go          | 7 ++++---
commands/comment_add.go      | 7 ++++---
commands/deselect.go         | 3 ++-
commands/label.go            | 7 ++++---
commands/label_add.go        | 7 ++++---
commands/label_rm.go         | 7 ++++---
commands/ls-labels.go        | 3 ++-
commands/ls.go               | 3 ++-
commands/pull.go             | 7 ++++---
commands/push.go             | 7 ++++---
commands/root.go             | 4 ----
commands/select.go           | 3 ++-
commands/show.go             | 7 ++++---
commands/status.go           | 7 ++++---
commands/status_close.go     | 7 ++++---
commands/status_open.go      | 7 ++++---
commands/termui.go           | 7 ++++---
commands/title.go            | 7 ++++---
commands/title_edit.go       | 7 ++++---
commands/webui.go            | 7 ++++---
25 files changed, 90 insertions(+), 70 deletions(-)

Detailed changes

commands/add.go 🔗

@@ -53,9 +53,10 @@ func runAddBug(cmd *cobra.Command, args []string) error {
 }
 
 var addCmd = &cobra.Command{
-	Use:   "add",
-	Short: "Create a new bug",
-	RunE:  runAddBug,
+	Use:     "add",
+	Short:   "Create a new bug",
+	PreRunE: loadRepo,
+	RunE:    runAddBug,
 }
 
 func init() {

commands/bridge.go 🔗

@@ -28,10 +28,11 @@ func runBridge(cmd *cobra.Command, args []string) error {
 }
 
 var bridgeCmd = &cobra.Command{
-	Use:   "bridge",
-	Short: "Configure and use bridges to other bug trackers",
-	RunE:  runBridge,
-	Args:  cobra.NoArgs,
+	Use:     "bridge",
+	Short:   "Configure and use bridges to other bug trackers",
+	PreRunE: loadRepo,
+	RunE:    runBridge,
+	Args:    cobra.NoArgs,
 }
 
 func init() {

commands/bridge_configure.go 🔗

@@ -88,9 +88,10 @@ func promptName() (string, error) {
 }
 
 var bridgeConfigureCmd = &cobra.Command{
-	Use:   "configure",
-	Short: "Configure a new bridge",
-	RunE:  runBridgeConfigure,
+	Use:     "configure",
+	Short:   "Configure a new bridge",
+	PreRunE: loadRepo,
+	RunE:    runBridgeConfigure,
 }
 
 func init() {

commands/bridge_pull.go 🔗

@@ -35,9 +35,10 @@ func runBridgePull(cmd *cobra.Command, args []string) error {
 }
 
 var bridgePullCmd = &cobra.Command{
-	Use:   "pull [<name>]",
-	Short: "Pull updates",
-	RunE:  runBridgePull,
+	Use:     "pull [<name>]",
+	Short:   "Pull updates",
+	PreRunE: loadRepo,
+	RunE:    runBridgePull,
 }
 
 func init() {

commands/bridge_rm.go 🔗

@@ -22,10 +22,11 @@ func runBridgeRm(cmd *cobra.Command, args []string) error {
 }
 
 var bridgeRmCmd = &cobra.Command{
-	Use:   "rm name <name>",
-	Short: "Delete a configured bridge",
-	RunE:  runBridgeRm,
-	Args:  cobra.ExactArgs(1),
+	Use:     "rm name <name>",
+	Short:   "Delete a configured bridge",
+	PreRunE: loadRepo,
+	RunE:    runBridgeRm,
+	Args:    cobra.ExactArgs(1),
 }
 
 func init() {

commands/comment.go 🔗

@@ -43,9 +43,10 @@ func commentsTextOutput(comments []bug.Comment) {
 }
 
 var commentCmd = &cobra.Command{
-	Use:   "comment [<id>]",
-	Short: "Display or add comments",
-	RunE:  runComment,
+	Use:     "comment [<id>]",
+	Short:   "Display or add comments",
+	PreRunE: loadRepo,
+	RunE:    runComment,
 }
 
 func init() {

commands/comment_add.go 🔗

@@ -53,9 +53,10 @@ func runCommentAdd(cmd *cobra.Command, args []string) error {
 }
 
 var commentAddCmd = &cobra.Command{
-	Use:   "add [<id>]",
-	Short: "Add a new comment",
-	RunE:  runCommentAdd,
+	Use:     "add [<id>]",
+	Short:   "Add a new comment",
+	PreRunE: loadRepo,
+	RunE:    runCommentAdd,
 }
 
 func init() {

commands/deselect.go 🔗

@@ -29,7 +29,8 @@ git bug comment
 git bug status
 git bug deselect
 `,
-	RunE: runDeselect,
+	PreRunE: loadRepo,
+	RunE:    runDeselect,
 }
 
 func init() {

commands/label.go 🔗

@@ -30,9 +30,10 @@ func runLabel(cmd *cobra.Command, args []string) error {
 }
 
 var labelCmd = &cobra.Command{
-	Use:   "label [<id>]",
-	Short: "Display, add or remove labels",
-	RunE:  runLabel,
+	Use:     "label [<id>]",
+	Short:   "Display, add or remove labels",
+	PreRunE: loadRepo,
+	RunE:    runLabel,
 }
 
 func init() {

commands/label_add.go 🔗

@@ -34,9 +34,10 @@ func runLabelAdd(cmd *cobra.Command, args []string) error {
 }
 
 var labelAddCmd = &cobra.Command{
-	Use:   "add [<id>] <label>[...]",
-	Short: "Add a label",
-	RunE:  runLabelAdd,
+	Use:     "add [<id>] <label>[...]",
+	Short:   "Add a label",
+	PreRunE: loadRepo,
+	RunE:    runLabelAdd,
 }
 
 func init() {

commands/label_rm.go 🔗

@@ -34,9 +34,10 @@ func runLabelRm(cmd *cobra.Command, args []string) error {
 }
 
 var labelRmCmd = &cobra.Command{
-	Use:   "rm [<id>] <label>[...]",
-	Short: "Remove a label",
-	RunE:  runLabelRm,
+	Use:     "rm [<id>] <label>[...]",
+	Short:   "Remove a label",
+	PreRunE: loadRepo,
+	RunE:    runLabelRm,
 }
 
 func init() {

commands/ls-labels.go 🔗

@@ -29,7 +29,8 @@ var lsLabelCmd = &cobra.Command{
 	Long: `List valid labels.
 
 Note: in the future, a proper label policy could be implemented where valid labels are defined in a configuration file. Until that, the default behavior is to return the list of labels already used.`,
-	RunE: runLsLabel,
+	PreRunE: loadRepo,
+	RunE:    runLsLabel,
 }
 
 func init() {

commands/ls.go 🔗

@@ -139,7 +139,8 @@ git bug ls status:open sort:edit-desc
 List closed bugs sorted by creation with flags:
 git bug ls --status closed --by creation
 `,
-	RunE: runLsBug,
+	PreRunE: loadRepo,
+	RunE:    runLsBug,
 }
 
 func init() {

commands/pull.go 🔗

@@ -51,9 +51,10 @@ func runPull(cmd *cobra.Command, args []string) error {
 
 // showCmd defines the "push" subcommand.
 var pullCmd = &cobra.Command{
-	Use:   "pull [<remote>]",
-	Short: "Pull bugs update from a git remote",
-	RunE:  runPull,
+	Use:     "pull [<remote>]",
+	Short:   "Pull bugs update from a git remote",
+	PreRunE: loadRepo,
+	RunE:    runPull,
 }
 
 func init() {

commands/push.go 🔗

@@ -36,9 +36,10 @@ func runPush(cmd *cobra.Command, args []string) error {
 
 // showCmd defines the "push" subcommand.
 var pushCmd = &cobra.Command{
-	Use:   "push [<remote>]",
-	Short: "Push bugs update to a git remote",
-	RunE:  runPush,
+	Use:     "push [<remote>]",
+	Short:   "Push bugs update to a git remote",
+	PreRunE: loadRepo,
+	RunE:    runPush,
 }
 
 func init() {

commands/root.go 🔗

@@ -38,10 +38,6 @@ the same git remote your are already using to collaborate with other peoples.
 		}
 	},
 
-	// Load the repo before any command execution
-	// Note, this concern only commands that actually have a Run function
-	PersistentPreRunE: loadRepo,
-
 	DisableAutoGenTag: true,
 
 	// Custom bash code to connect the git completion for "git bug" to the

commands/select.go 🔗

@@ -44,7 +44,8 @@ var selectCmd = &cobra.Command{
 git bug comment
 git bug status
 `,
-	RunE: runSelect,
+	PreRunE: loadRepo,
+	RunE:    runSelect,
 }
 
 func init() {

commands/show.go 🔗

@@ -73,9 +73,10 @@ func runShowBug(cmd *cobra.Command, args []string) error {
 }
 
 var showCmd = &cobra.Command{
-	Use:   "show [<id>]",
-	Short: "Display the details of a bug",
-	RunE:  runShowBug,
+	Use:     "show [<id>]",
+	Short:   "Display the details of a bug",
+	PreRunE: loadRepo,
+	RunE:    runShowBug,
 }
 
 func init() {

commands/status.go 🔗

@@ -28,9 +28,10 @@ func runStatus(cmd *cobra.Command, args []string) error {
 }
 
 var statusCmd = &cobra.Command{
-	Use:   "status [<id>]",
-	Short: "Display or change a bug status",
-	RunE:  runStatus,
+	Use:     "status [<id>]",
+	Short:   "Display or change a bug status",
+	PreRunE: loadRepo,
+	RunE:    runStatus,
 }
 
 func init() {

commands/status_close.go 🔗

@@ -27,9 +27,10 @@ func runStatusClose(cmd *cobra.Command, args []string) error {
 }
 
 var closeCmd = &cobra.Command{
-	Use:   "close [<id>]",
-	Short: "Mark a bug as closed",
-	RunE:  runStatusClose,
+	Use:     "close [<id>]",
+	Short:   "Mark a bug as closed",
+	PreRunE: loadRepo,
+	RunE:    runStatusClose,
 }
 
 func init() {

commands/status_open.go 🔗

@@ -27,9 +27,10 @@ func runStatusOpen(cmd *cobra.Command, args []string) error {
 }
 
 var openCmd = &cobra.Command{
-	Use:   "open [<id>]",
-	Short: "Mark a bug as open",
-	RunE:  runStatusOpen,
+	Use:     "open [<id>]",
+	Short:   "Mark a bug as open",
+	PreRunE: loadRepo,
+	RunE:    runStatusOpen,
 }
 
 func init() {

commands/termui.go 🔗

@@ -17,9 +17,10 @@ func runTermUI(cmd *cobra.Command, args []string) error {
 }
 
 var termUICmd = &cobra.Command{
-	Use:   "termui",
-	Short: "Launch the terminal UI",
-	RunE:  runTermUI,
+	Use:     "termui",
+	Short:   "Launch the terminal UI",
+	PreRunE: loadRepo,
+	RunE:    runTermUI,
 }
 
 func init() {

commands/title.go 🔗

@@ -28,9 +28,10 @@ func runTitle(cmd *cobra.Command, args []string) error {
 }
 
 var titleCmd = &cobra.Command{
-	Use:   "title [<id>]",
-	Short: "Display or change a title",
-	RunE:  runTitle,
+	Use:     "title [<id>]",
+	Short:   "Display or change a title",
+	PreRunE: loadRepo,
+	RunE:    runTitle,
 }
 
 func init() {

commands/title_edit.go 🔗

@@ -51,9 +51,10 @@ func runTitleEdit(cmd *cobra.Command, args []string) error {
 }
 
 var titleEditCmd = &cobra.Command{
-	Use:   "edit [<id>]",
-	Short: "Edit a title",
-	RunE:  runTitleEdit,
+	Use:     "edit [<id>]",
+	Short:   "Edit a title",
+	PreRunE: loadRepo,
+	RunE:    runTitleEdit,
 }
 
 func init() {

commands/webui.go 🔗

@@ -223,9 +223,10 @@ func (gufh *gitUploadFileHandler) ServeHTTP(rw http.ResponseWriter, r *http.Requ
 }
 
 var webUICmd = &cobra.Command{
-	Use:   "webui",
-	Short: "Launch the web UI",
-	RunE:  runWebUI,
+	Use:     "webui",
+	Short:   "Launch the web UI",
+	PreRunE: loadRepo,
+	RunE:    runWebUI,
 }
 
 func init() {