From f643dbfd3a52715ef6e578ee956866b6ea22be8b Mon Sep 17 00:00:00 2001 From: Clement Sam Date: Wed, 12 Aug 2020 08:05:25 +0000 Subject: [PATCH] refactor: persist --repo flag across mr and issue subcommand --- commands/issue.go | 3 ++- commands/issue_close.go | 6 +++++- commands/issue_create.go | 4 ++++ commands/issue_delete.go | 7 +++++-- commands/issue_list.go | 6 ++++-- commands/issue_reopen.go | 6 +++++- commands/issue_subscribe.go | 6 +++++- commands/issue_unsubscribe.go | 6 +++++- commands/issue_view.go | 4 ++-- commands/label.go | 1 + commands/label_create.go | 7 +++++-- commands/label_list.go | 7 +++++-- commands/mr.go | 1 + commands/mr_approve.go | 5 ++++- commands/mr_close.go | 6 ++++-- commands/mr_create.go | 4 ++++ commands/mr_delete.go | 6 ++++-- commands/mr_issues.go | 5 ++++- commands/mr_list.go | 5 ++++- commands/mr_merge.go | 4 ++++ commands/mr_reopen.go | 5 ++++- commands/mr_revoke.go | 4 ++++ commands/{mr_browse.go => mr_show.go} | 3 ++- commands/mr_subscribe.go | 4 ++++ commands/mr_unsubscribe.go | 4 ++++ commands/mr_update.go | 4 ++++ commands/pipeline_delete.go | 4 ++++ commands/pipeline_list.go | 4 ++++ commands/repo_archive.go | 1 + commands/repo_clone.go | 1 + commands/repo_contributors.go | 9 ++++----- 31 files changed, 113 insertions(+), 29 deletions(-) rename commands/{mr_browse.go => mr_show.go} (81%) diff --git a/commands/issue.go b/commands/issue.go index 5b8c9a0b..9c32ff78 100644 --- a/commands/issue.go +++ b/commands/issue.go @@ -52,7 +52,7 @@ func displayIssue(hm *gitlab.Issue) { // mrCmd is merge request command var issueCmd = &cobra.Command{ - Use: "issue [flags]", + Use: "issue [command] [flags]", Short: `Create, view and manage remote issues`, Long: ``, Run: func(cmd *cobra.Command, args []string) { @@ -64,5 +64,6 @@ var issueCmd = &cobra.Command{ } func init() { + issueCmd.PersistentFlags().StringP("repo", "R","", "Select another repository using the OWNER/REPO format or the project ID. Supports group namespaces") RootCmd.AddCommand(issueCmd) } diff --git a/commands/issue_close.go b/commands/issue_close.go index 74327a7a..857b2e11 100644 --- a/commands/issue_close.go +++ b/commands/issue_close.go @@ -11,10 +11,11 @@ import ( ) var issueCloseCmd = &cobra.Command{ - Use: "close", + Use: "close ", Short: `Close an issue`, Long: ``, Aliases: []string{"unsub"}, + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { if len(args) > 1 { cmdErr(cmd, args) @@ -23,6 +24,9 @@ var issueCloseCmd = &cobra.Command{ if len(args) > 0 { issueID := strings.TrimSpace(args[0]) gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } l := &gitlab.UpdateIssueOptions{} l.StateEvent = gitlab.String("close") arrIds := strings.Split(strings.Trim(issueID, "[] "), ",") diff --git a/commands/issue_create.go b/commands/issue_create.go index 4245be0f..c0afd6e0 100644 --- a/commands/issue_create.go +++ b/commands/issue_create.go @@ -15,6 +15,7 @@ var issueCreateCmd = &cobra.Command{ Short: `Create an issue`, Long: ``, Aliases: []string{"new"}, + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if len(args) > 0 { cmdErr(cmd, args) @@ -69,6 +70,9 @@ var issueCreateCmd = &cobra.Command{ l.AssigneeIDs = t2 } gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } issue, _, err := gitlabClient.Issues.CreateIssue(repo, l) if err != nil { log.Fatal(err) diff --git a/commands/issue_delete.go b/commands/issue_delete.go index 7056e131..893a580f 100644 --- a/commands/issue_delete.go +++ b/commands/issue_delete.go @@ -9,10 +9,11 @@ import ( ) var issueDeleteCmd = &cobra.Command{ - Use: "delete", + Use: "delete ", Short: `Delete an issue`, Long: ``, Aliases: []string{"del"}, + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { if len(args) > 1 { cmdErr(cmd, args) @@ -21,7 +22,9 @@ var issueDeleteCmd = &cobra.Command{ if len(args) > 0 { issueID := strings.TrimSpace(args[0]) gitlabClient, repo := git.InitGitlabClient() - + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } arrIds := strings.Split(strings.Trim(issueID, "[] "), ",") for _, i2 := range arrIds { fmt.Println("Deleting Issue #" + i2) diff --git a/commands/issue_list.go b/commands/issue_list.go index 2bf9b29c..f4e2b382 100644 --- a/commands/issue_list.go +++ b/commands/issue_list.go @@ -12,7 +12,7 @@ var issueListCmd = &cobra.Command{ Short: `List project issues`, Long: ``, Aliases: []string{"ls"}, - Args: cobra.MaximumNArgs(3), + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { var state string if lb, _ := cmd.Flags().GetBool("all"); lb { @@ -40,7 +40,9 @@ var issueListCmd = &cobra.Command{ } gitlabClient, repo := git.InitGitlabClient() - + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } issues, _, err := gitlabClient.Issues.ListProjectIssues(repo, l) if err != nil { log.Fatal(err) diff --git a/commands/issue_reopen.go b/commands/issue_reopen.go index a5796086..262a10d4 100644 --- a/commands/issue_reopen.go +++ b/commands/issue_reopen.go @@ -11,10 +11,11 @@ import ( ) var issueReopenCmd = &cobra.Command{ - Use: "reopen", + Use: "reopen ", Short: `Reopen a closed issue`, Long: ``, Aliases: []string{"open"}, + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { if len(args) > 1 { cmdErr(cmd, args) @@ -23,6 +24,9 @@ var issueReopenCmd = &cobra.Command{ if len(args) > 0 { issueID := strings.TrimSpace(args[0]) gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } l := &gitlab.UpdateIssueOptions{} l.StateEvent = gitlab.String("reopen") arrIds := strings.Split(strings.Trim(issueID, "[] "), ",") diff --git a/commands/issue_subscribe.go b/commands/issue_subscribe.go index 2fbdf386..410ae3d0 100644 --- a/commands/issue_subscribe.go +++ b/commands/issue_subscribe.go @@ -9,10 +9,11 @@ import ( ) var issueSubscribeCmd = &cobra.Command{ - Use: "subscribe", + Use: "subscribe ", Short: `Subscribe to an issue`, Long: ``, Aliases: []string{"sub"}, + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { if len(args) > 1 { cmdErr(cmd, args) @@ -21,6 +22,9 @@ var issueSubscribeCmd = &cobra.Command{ if len(args) > 0 { mergeID := strings.TrimSpace(args[0]) gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } arrIds := strings.Split(strings.Trim(mergeID, "[] "), ",") for _, i2 := range arrIds { fmt.Println("Subscribing to Issue #" + i2) diff --git a/commands/issue_unsubscribe.go b/commands/issue_unsubscribe.go index e32e5bd3..8bd5c720 100644 --- a/commands/issue_unsubscribe.go +++ b/commands/issue_unsubscribe.go @@ -9,10 +9,11 @@ import ( ) var issueUnsubscribeCmd = &cobra.Command{ - Use: "unsubscribe", + Use: "unsubscribe ", Short: `Unsubscribe to an issue`, Long: ``, Aliases: []string{"unsub"}, + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { if len(args) > 1 { cmdErr(cmd, args) @@ -21,6 +22,9 @@ var issueUnsubscribeCmd = &cobra.Command{ if len(args) > 0 { mergeID := strings.TrimSpace(args[0]) gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } arrIds := strings.Split(strings.Trim(mergeID, "[] "), ",") for _, i2 := range arrIds { fmt.Println("Unsubscribing to Issue #" + i2) diff --git a/commands/issue_view.go b/commands/issue_view.go index 239d7ec4..5fd74168 100644 --- a/commands/issue_view.go +++ b/commands/issue_view.go @@ -17,11 +17,11 @@ import ( ) var issueViewCmd = &cobra.Command{ - Use: "view [flags]", + Use: "view ", Short: `Display the title, body, and other information about an issue.`, Long: ``, Aliases: []string{"show"}, - Args: cobra.MaximumNArgs(3), + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 || len(args) >1 { cmdErr(cmd, args) diff --git a/commands/label.go b/commands/label.go index 3741c5cb..fba3a97e 100644 --- a/commands/label.go +++ b/commands/label.go @@ -16,5 +16,6 @@ var labelCmd = &cobra.Command{ } func init() { + labelCmd.PersistentFlags().StringP("repo", "R","", "Select another repository using the OWNER/REPO format. Supports group namespaces") RootCmd.AddCommand(labelCmd) } diff --git a/commands/label_create.go b/commands/label_create.go index 986da6f5..09c237fe 100644 --- a/commands/label_create.go +++ b/commands/label_create.go @@ -8,17 +8,20 @@ import ( ) var labelCreateCmd = &cobra.Command{ - Use: "create [flags]", + Use: "create [flags]", Short: `Create labels for repository/project`, Long: ``, Aliases: []string{"new"}, - Args: cobra.MaximumNArgs(1), + Args: cobra.ExactArgs(0), Run: createLabel, } func createLabel(cmd *cobra.Command, args []string) { gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } l := &gitlab.CreateLabelOptions{} if s, _ := cmd.Flags().GetString("name"); s != "" { diff --git a/commands/label_list.go b/commands/label_list.go index af3d9130..06bc4384 100644 --- a/commands/label_list.go +++ b/commands/label_list.go @@ -9,16 +9,19 @@ import ( ) var labelListCmd = &cobra.Command{ - Use: "list [flags]", + Use: "list [flags]", Short: `List labels in repository`, Long: ``, Aliases: []string{"ls"}, - Args: cobra.MaximumNArgs(1), + Args: cobra.ExactArgs(0), Run: listLabels, } func listLabels(cmd *cobra.Command, args []string) { gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } // List all labels labels, _, err := gitlabClient.Labels.ListLabels(repo, nil) if err != nil { diff --git a/commands/mr.go b/commands/mr.go index c8aa2352..3659df42 100644 --- a/commands/mr.go +++ b/commands/mr.go @@ -55,5 +55,6 @@ var mrCmd = &cobra.Command{ } func init() { + mrCmd.PersistentFlags().StringP("repo", "R","", "Select another repository using the OWNER/REPO format or the project ID. Supports group namespaces") RootCmd.AddCommand(mrCmd) } diff --git a/commands/mr_approve.go b/commands/mr_approve.go index 918c4217..e5e74700 100644 --- a/commands/mr_approve.go +++ b/commands/mr_approve.go @@ -16,7 +16,7 @@ var mrApproveCmd = &cobra.Command{ Short: `Approve merge requests`, Long: ``, Aliases: []string{"ls"}, - Args: cobra.MaximumNArgs(1), + Args: cobra.ExactArgs(1), Run: approveMergeRequest, } @@ -33,6 +33,9 @@ func approveMergeRequest(cmd *cobra.Command, args []string) { fmt.Println(aurora.Yellow("Approving Merge Request #" + mergeID + "...")) gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } _, resp, _ := gitlabClient.MergeRequestApprovals.ApproveMergeRequest(repo, manip.StringToInt(mergeID), l) if resp != nil { if resp.StatusCode == 201 { diff --git a/commands/mr_close.go b/commands/mr_close.go index bd58c322..8332387f 100644 --- a/commands/mr_close.go +++ b/commands/mr_close.go @@ -14,8 +14,7 @@ var mrCloseCmd = &cobra.Command{ Use: "close ", Short: `Close merge requests`, Long: ``, - Aliases: []string{"ls"}, - Args: cobra.MaximumNArgs(1), + Args: cobra.ExactArgs(1), Run: closeMergeRequestState, } @@ -23,6 +22,9 @@ func closeMergeRequestState(cmd *cobra.Command, args []string) { if len(args) > 0 { mergeID := strings.Trim(args[0], " ") gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } l := &gitlab.UpdateMergeRequestOptions{} l.StateEvent = gitlab.String("close") arrIds := strings.Split(strings.Trim(mergeID, "[] "), ",") diff --git a/commands/mr_create.go b/commands/mr_create.go index f360d556..18701b17 100644 --- a/commands/mr_create.go +++ b/commands/mr_create.go @@ -15,6 +15,7 @@ var mrCreateCmd = &cobra.Command{ Short: `Create new merge request`, Long: ``, Aliases: []string{"new"}, + Args: cobra.ExactArgs(0), Run: func(cmd *cobra.Command, args []string) { if len(args) > 0 { cmdErr(cmd, args) @@ -84,6 +85,9 @@ var mrCreateCmd = &cobra.Command{ } gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } if c, _ := cmd.Flags().GetBool("create-source-branch"); c { lb := &gitlab.CreateBranchOptions{ Branch: gitlab.String(sourceBranch), diff --git a/commands/mr_delete.go b/commands/mr_delete.go index 2d78c54e..558a0364 100644 --- a/commands/mr_delete.go +++ b/commands/mr_delete.go @@ -15,7 +15,7 @@ var mrDeleteCmd = &cobra.Command{ Short: `Delete merge requests`, Long: ``, Aliases: []string{"del"}, - Args: cobra.MaximumNArgs(1), + Args: cobra.ExactArgs(1), Example: "$ glab delete 123", RunE: deleteMergeRequest, } @@ -25,7 +25,9 @@ func deleteMergeRequest(cmd *cobra.Command, args []string) error { if len(args) > 0 { mergeID := strings.Trim(args[0], " ") gitlabClient, repo := git.InitGitlabClient() - + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } arrIds := strings.Split(strings.Trim(mergeID, "[] "), ",") for _, i2 := range arrIds { fmt.Println("Deleting Merge Request #" + i2) diff --git a/commands/mr_issues.go b/commands/mr_issues.go index b4622078..d4a24f3e 100644 --- a/commands/mr_issues.go +++ b/commands/mr_issues.go @@ -14,7 +14,7 @@ var mrIssuesCmd = &cobra.Command{ Short: `Get issues related to a particular merge request.`, Long: ``, Aliases: []string{"issue"}, - Args: cobra.MaximumNArgs(1), + Args: cobra.ExactArgs(1), Example: "$ glab mr issues 46", Run: issuesRelatedMergeRequest, } @@ -24,6 +24,9 @@ func issuesRelatedMergeRequest(cmd *cobra.Command, args []string) { mergeID := strings.Trim(args[0], " ") l := &gitlab.GetIssuesClosedOnMergeOptions{} gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } mr, _, err := gitlabClient.MergeRequests.GetIssuesClosedOnMerge(repo, manip.StringToInt(mergeID), l) if err != nil { er(err) diff --git a/commands/mr_list.go b/commands/mr_list.go index 6957f63e..e5171fdd 100644 --- a/commands/mr_list.go +++ b/commands/mr_list.go @@ -11,7 +11,7 @@ var mrListCmd = &cobra.Command{ Short: `List merge requests`, Long: ``, Aliases: []string{"ls"}, - Args: cobra.MaximumNArgs(3), + Args: cobra.ExactArgs(0), RunE: listMergeRequest, } @@ -41,6 +41,9 @@ func listMergeRequest(cmd *cobra.Command, args []string) error { } gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } mergeRequests, _, err := gitlabClient.MergeRequests.ListProjectMergeRequests(repo, l) if err != nil { return err diff --git a/commands/mr_merge.go b/commands/mr_merge.go index 402066d5..b9ca42b2 100644 --- a/commands/mr_merge.go +++ b/commands/mr_merge.go @@ -17,6 +17,7 @@ var mrMergeCmd = &cobra.Command{ Short: `Merge/Accept merge requests`, Long: ``, Aliases: []string{"accept"}, + Args: cobra.ExactArgs(1), Run: acceptMergeRequest, } @@ -42,6 +43,9 @@ func acceptMergeRequest(cmd *cobra.Command, args []string) { l.SHA = gitlab.String(m) } gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } mr, resp, _ := gitlabClient.MergeRequests.AcceptMergeRequest(repo, manip.StringToInt(mergeID), l) fmt.Println(aurora.Yellow("Accepting Merge Request #" + mergeID + "...")) diff --git a/commands/mr_reopen.go b/commands/mr_reopen.go index dd32088e..580acd79 100644 --- a/commands/mr_reopen.go +++ b/commands/mr_reopen.go @@ -15,7 +15,7 @@ var mrReopenCmd = &cobra.Command{ Short: `Reopen merge requests`, Long: ``, Aliases: []string{"open"}, - Args: cobra.MaximumNArgs(1), + Args: cobra.ExactArgs(1), Run: reopenMergeRequestState, } @@ -23,6 +23,9 @@ func reopenMergeRequestState(cmd *cobra.Command, args []string) { if len(args) > 0 { mergeID := strings.Trim(args[0], " ") gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } l := &gitlab.UpdateMergeRequestOptions{} l.StateEvent = gitlab.String("reopen") arrIds := strings.Split(strings.Trim(mergeID, "[] "), ",") diff --git a/commands/mr_revoke.go b/commands/mr_revoke.go index 741c0076..3ace5ae7 100644 --- a/commands/mr_revoke.go +++ b/commands/mr_revoke.go @@ -16,6 +16,7 @@ var mrRevokeCmd = &cobra.Command{ Short: `Revoke approval on a merge request `, Long: ``, Aliases: []string{"unapprove"}, + Args: cobra.ExactArgs(1), Run: revokeMergeRequest, } @@ -25,6 +26,9 @@ func revokeMergeRequest(cmd *cobra.Command, args []string) { fmt.Println(aurora.Yellow("Revoking approval for Merge Request #" + mergeID + "...")) gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } resp, _ := gitlabClient.MergeRequestApprovals.UnapproveMergeRequest(repo, manip.StringToInt(mergeID)) if resp != nil { if resp.StatusCode == 201 { diff --git a/commands/mr_browse.go b/commands/mr_show.go similarity index 81% rename from commands/mr_browse.go rename to commands/mr_show.go index b9c27e68..a971eb68 100644 --- a/commands/mr_browse.go +++ b/commands/mr_show.go @@ -5,10 +5,11 @@ import ( ) var mrBrowseCmd = &cobra.Command{ - Use: "browse [remote] ", + Use: "browse [help]", Aliases: []string{"b"}, Short: "View merge request in a browser", Long: ``, + Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { }, diff --git a/commands/mr_subscribe.go b/commands/mr_subscribe.go index 6e8b93cf..3b269a1e 100644 --- a/commands/mr_subscribe.go +++ b/commands/mr_subscribe.go @@ -16,6 +16,7 @@ var mrSubscribeCmd = &cobra.Command{ Short: `Subscribe to merge requests`, Long: ``, Aliases: []string{"sub"}, + Args: cobra.ExactArgs(1), Run: subscribeSubscribeRequest, } @@ -23,6 +24,9 @@ func subscribeSubscribeRequest(cmd *cobra.Command, args []string) { if len(args) > 0 { mergeID := strings.Trim(args[0], " ") gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } arrIds := strings.Split(strings.Trim(mergeID, "[] "), ",") for _, i2 := range arrIds { fmt.Println("Subscribing to merge Request #" + i2) diff --git a/commands/mr_unsubscribe.go b/commands/mr_unsubscribe.go index 8157e7b3..0e61b0ad 100644 --- a/commands/mr_unsubscribe.go +++ b/commands/mr_unsubscribe.go @@ -16,6 +16,7 @@ var mrUnsubscribeCmd = &cobra.Command{ Short: `Unsubscribe to merge requests`, Long: ``, Aliases: []string{"unsub"}, + Args: cobra.ExactArgs(1), Run: unsubscribeMergeRequest, } @@ -23,6 +24,9 @@ func unsubscribeMergeRequest(cmd *cobra.Command, args []string) { if len(args) > 0 { mergeID := strings.Trim(args[0], " ") gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } arrIds := strings.Split(strings.Trim(mergeID, "[] "), ",") for _, i2 := range arrIds { fmt.Println("Unsubscribing Merge Request #" + i2) diff --git a/commands/mr_update.go b/commands/mr_update.go index 2dfa7af6..f3fdc850 100644 --- a/commands/mr_update.go +++ b/commands/mr_update.go @@ -12,6 +12,7 @@ var mrUpdateCmd = &cobra.Command{ Use: "update ", Short: `Update merge requests`, Long: ``, + Args: cobra.ExactArgs(1), Run: updateMergeRequest, } @@ -29,6 +30,9 @@ func updateMergeRequest(cmd *cobra.Command, args []string) { l.Description = gitlab.String(m) } gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } mr, _, err := gitlabClient.MergeRequests.UpdateMergeRequest(repo, manip.StringToInt(mergeID), l) if err != nil { er(err) diff --git a/commands/pipeline_delete.go b/commands/pipeline_delete.go index b14dafea..76679a7f 100644 --- a/commands/pipeline_delete.go +++ b/commands/pipeline_delete.go @@ -21,11 +21,15 @@ var pipelineDeleteCmd = &cobra.Command{ $ glab pipeline delete 12,34,2 `), Long: ``, + Args: cobra.ExactArgs(1), Run: deletePipeline, } func deletePipeline(cmd *cobra.Command, args []string) { gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } if m, _ := cmd.Flags().GetString("status"); m != "" { l := &gitlab.ListProjectPipelinesOptions{} l.Status = gitlab.BuildState(gitlab.BuildStateValue(m)) diff --git a/commands/pipeline_list.go b/commands/pipeline_list.go index 5f6cebd0..16edc877 100644 --- a/commands/pipeline_list.go +++ b/commands/pipeline_list.go @@ -15,11 +15,15 @@ var pipelineListCmd = &cobra.Command{ $ glab pipeline list --state=failed `), Long: ``, + Args: cobra.ExactArgs(0), Run: listPipelines, } func listPipelines(cmd *cobra.Command, args []string) { gitlabClient, repo := git.InitGitlabClient() + if r, _ := cmd.Flags().GetString("repo"); r != "" { + repo = r + } l := &gitlab.ListProjectPipelinesOptions{} if m, _ := cmd.Flags().GetString("status"); m != "" { l.Status = gitlab.BuildState(gitlab.BuildStateValue(m)) diff --git a/commands/repo_archive.go b/commands/repo_archive.go index 0d2674a5..2de78450 100644 --- a/commands/repo_archive.go +++ b/commands/repo_archive.go @@ -29,6 +29,7 @@ var repoArchiveCmd = &cobra.Command{ - namespace/repo - namespace/group/repo `), + Args: cobra.MaximumNArgs(2), Run: func (cmd *cobra.Command, args []string) { repo := config.GetRepo() var name string diff --git a/commands/repo_clone.go b/commands/repo_clone.go index 223dac76..1854db06 100644 --- a/commands/repo_clone.go +++ b/commands/repo_clone.go @@ -25,6 +25,7 @@ var repoCloneCmd = &cobra.Command{ - namespace/group/repo - url/namespace/group/repo `), + Args: cobra.MaximumNArgs(2), Run: func(cmd *cobra.Command, args []string) { if len(args) == 0 { cmdErr(cmd, args) diff --git a/commands/repo_contributors.go b/commands/repo_contributors.go index fb40e7fa..488d60b8 100644 --- a/commands/repo_contributors.go +++ b/commands/repo_contributors.go @@ -10,13 +10,11 @@ import ( ) var repoContributorsCmd = &cobra.Command{ - Use: "contributors [flags]", - Short: `Get an archive of the repository.`, + Use: "contributors [flags]", + Short: `Get contributors of the repository.`, Example: heredoc.Doc(` - $ glab repo archive profclems/glab + $ glab repo contributors $ glab repo archive // Downloads zip file of current repository - $ glab repo clone profclems/glab mydirectory // Clones repo into mydirectory - $ glab repo clone profclems/glab --format=zip // Finds repo for current user and download in zip format `), Long: heredoc.Doc(` Clone supports these shorthands @@ -24,6 +22,7 @@ var repoContributorsCmd = &cobra.Command{ - namespace/repo - namespace/group/repo `), + Args: cobra.ExactArgs(0), Aliases: []string{"users"}, Run: func (cmd *cobra.Command, args []string) { gitlabClient, repo := git.InitGitlabClient()