Skip to content

Commit

Permalink
todo: Fix ability to specify remote on command line
Browse files Browse the repository at this point in the history
It is not possible to add a todo item from any other remote other than
'origin'.  This is a problem if a repo has multiple remotes.

Fix the ability of the 'lab todo mr' and 'lab todo issue' commands to
specify a remote.

Signed-off-by: Prarit Bhargava <[email protected]>
  • Loading branch information
prarit committed Feb 22, 2022
1 parent bff0272 commit a19fdaa
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
17 changes: 6 additions & 11 deletions cmd/todo_issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,26 @@ package cmd

import (
"fmt"
lab "github.com/zaquestion/lab/internal/gitlab"
"strconv"

"github.com/MakeNowJust/heredoc/v2"
"github.com/spf13/cobra"
lab "github.com/zaquestion/lab/internal/gitlab"
)

var todoIssueCmd = &cobra.Command{
Use: "issue",
Use: "issue [remote] <id>",
Short: "Add a Issue to Todo list",
Example: heredoc.Doc(`
lab todo issue 5678`),
lab todo issue 5678 #adds issue 5678 to user's Todo list
lab todo issue otherRemote 91011`),
PersistentPreRun: labPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, err := getRemoteName("")
if err != nil {
log.Fatal(err)
}

num, err := strconv.Atoi(args[0])
rn, num, err := parseArgsRemoteAndID(args)
if err != nil {
log.Fatal(err)
}

todoAddIssue(rn, num)
todoAddIssue(rn, int(num))

},
}
Expand Down
19 changes: 8 additions & 11 deletions cmd/todo_mr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,26 @@ package cmd

import (
"fmt"
"strconv"

"github.com/MakeNowJust/heredoc/v2"
"github.com/spf13/cobra"
lab "github.com/zaquestion/lab/internal/gitlab"
)

var todoMRCmd = &cobra.Command{
Use: "mr",
Short: "Add a Merge Request to Todo list",
Example: "lab todo mr 1234 #adds MR 1234 to user's Todo list",
Use: "mr [remote] <id>",
Short: "Add a Merge Request to Todo list",
Example: heredoc.Doc(`
lab todo mr 1234 #adds MR 1234 to user's Todo list
lab todo mr otherRemote 5678`),
PersistentPreRun: labPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, err := getRemoteName("")
rn, num, err := parseArgsRemoteAndID(args)
if err != nil {
log.Fatal(err)
}

num, err := strconv.Atoi(args[0])
if err != nil {
log.Fatal(err)
}

todoAddMergeRequest(rn, num)
todoAddMergeRequest(rn, int(num))
},
}

Expand Down

0 comments on commit a19fdaa

Please sign in to comment.