Skip to content

Commit 10cc0e2

Browse files
committed
fix(governctl): Tidy up command parsing
Signed-off-by: Cezar Craciunoiu <cezar.craciunoiu@gmail.com>
1 parent bf978f5 commit 10cc0e2

File tree

7 files changed

+8
-25
lines changed

7 files changed

+8
-25
lines changed

cmd/governctl/main.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,7 @@ func main() {
7676
ctx = kitcfg.WithConfigManager(ctx, cfgm)
7777

7878
// Attribute all configuration flags and command-line argument values
79-
cmd, args, err := cmd.Find(os.Args[1:])
80-
if err != nil {
81-
fmt.Println(err)
82-
os.Exit(1)
83-
}
84-
if err := cmdfactory.AttributeFlags(cmd, &cfg, args...); err != nil {
79+
if err := cmdfactory.AttributeFlags(cmd, &cfg, os.Args[1:]...); err != nil {
8580
fmt.Println(err)
8681
os.Exit(1)
8782
}

cmd/governctl/pr/check/merable.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewMergable() *cobra.Command {
5050
cmd, err := cmdfactory.New(&Mergable{}, cobra.Command{
5151
Use: "mergable [OPTIONS] ORG/REPO/PRID",
5252
Short: "Check whether a PR satisfies the provided merge requirements",
53-
Args: cmdutils.OrgRepoAndPullRequestNumber(),
53+
Args: cobra.MaximumNArgs(2),
5454
Annotations: map[string]string{
5555
cmdfactory.AnnotationHelpGroup: "pr",
5656
},

cmd/governctl/pr/check/patch.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func NewPatch() *cobra.Command {
4949
cmd, err := cmdfactory.New(&Patch{}, cobra.Command{
5050
Use: "patch [OPTIONS] ORG/REPO/PRID",
5151
Short: "Run checkpatch against a pull request",
52-
Args: cmdutils.OrgRepoAndPullRequestNumber(),
52+
Args: cobra.MaximumNArgs(2),
5353
Annotations: map[string]string{
5454
cmdfactory.AnnotationHelpGroup: "pr",
5555
},
@@ -68,6 +68,8 @@ func NewPatch() *cobra.Command {
6868
func (opts *Patch) Run(ctx context.Context, args []string) error {
6969
var extraIgnores []string
7070

71+
fmt.Printf("args: %v\n", args)
72+
7173
ghOrg, ghRepo, ghPrId, err := cmdutils.ParseOrgRepoAndPullRequestArgs(args)
7274
if err != nil {
7375
return err

cmd/governctl/pr/merge.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func NewMerge() *cobra.Command {
6464
cmd, err := cmdfactory.New(&Merge{}, cobra.Command{
6565
Use: "merge [OPTIONS] ORG/REPO/PRID",
6666
Short: "Merge a pull request",
67-
Args: cmdutils.OrgRepoAndPullRequestNumber(),
67+
Args: cobra.MaximumNArgs(2),
6868
Annotations: map[string]string{
6969
cmdfactory.AnnotationHelpGroup: "pr",
7070
},

cmd/governctl/pr/sync/labels.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func NewLabels() *cobra.Command {
3434
cmd, err := cmdfactory.New(&Labels{}, cobra.Command{
3535
Use: "labels [OPTIONS] ORG/REPO/PRID",
3636
Short: "Synchronise a pull request's labels",
37-
Args: cmdutils.OrgRepoAndPullRequestNumber(),
37+
Args: cobra.MaximumNArgs(2),
3838
Annotations: map[string]string{
3939
cmdfactory.AnnotationHelpGroup: "pr",
4040
},

cmd/governctl/pr/sync/reviewers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func NewReviewers() *cobra.Command {
4242
cmd, err := cmdfactory.New(&Reviewers{}, cobra.Command{
4343
Use: "reviewers [OPTIONS] ORG/REPO/PRID",
4444
Short: "Synchronise a pull request's assignees (maintainers) and reviewers",
45-
Args: cmdutils.OrgRepoAndPullRequestNumber(),
45+
Args: cobra.MaximumNArgs(2),
4646
Annotations: map[string]string{
4747
cmdfactory.AnnotationHelpGroup: "pr",
4848
},

internal/cmdutils/args.go

-14
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,8 @@ import (
1111
"os"
1212
"strconv"
1313
"strings"
14-
15-
"github.com/spf13/cobra"
16-
"kraftkit.sh/cmdfactory"
1714
)
1815

19-
// OrgRepoAndPullRequestNumber
20-
func OrgRepoAndPullRequestNumber() cobra.PositionalArgs {
21-
return func(_ *cobra.Command, args []string) error {
22-
if _, _, _, err := ParseOrgRepoAndPullRequestArgs(args); err != nil {
23-
return cmdfactory.FlagErrorf("%w", err)
24-
}
25-
26-
return nil
27-
}
28-
}
29-
3016
// ParseOrgRepoAndPullRequestArgs accepts input command-line arguments in the
3117
// following forms:
3218
//

0 commit comments

Comments
 (0)