Skip to content

Commit

Permalink
Merge pull request #436 from prarit/issue435
Browse files Browse the repository at this point in the history
Merge Flags and Configs
  • Loading branch information
prarit authored Sep 25, 2020
2 parents f68476e + 010a623 commit 97ffd5e
Show file tree
Hide file tree
Showing 43 changed files with 442 additions and 160 deletions.
7 changes: 4 additions & 3 deletions cmd/ci_lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@ import (

// ciLintCmd represents the lint command
var ciLintCmd = &cobra.Command{
Use: "lint",
Short: "Validate .gitlab-ci.yml against GitLab",
Long: ``,
Use: "lint",
Short: "Validate .gitlab-ci.yml against GitLab",
Long: ``,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
path := ".gitlab-ci.yml"
if len(args) == 1 {
Expand Down
2 changes: 2 additions & 0 deletions cmd/ci_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Project will be inferred from branch if not provided
Note: "lab ci create" differs from "lab ci trigger" which is a different API`,
Example: `lab ci create feature_branch
lab ci create -p engineering/integration_tests master`,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
pid, branch, err := getCIRunOptions(cmd, args)
if err != nil {
Expand Down Expand Up @@ -55,6 +56,7 @@ Note: "lab ci trigger" differs from "lab ci create" which is a different API`,
Example: `lab ci trigger feature_branch
lab ci trigger -p engineering/integration_tests master
lab ci trigger -p engineering/integration_tests -v foo=bar master`,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
pid, branch, err := getCIRunOptions(cmd, args)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/ci_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ var ciStatusCmd = &cobra.Command{
Long: ``,
Example: `lab ci status
lab ci status --wait`,
RunE: nil,
RunE: nil,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
var (
rn string
Expand Down
9 changes: 5 additions & 4 deletions cmd/ci_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import (

// ciLintCmd represents the lint command
var ciTraceCmd = &cobra.Command{
Use: "trace [remote [[branch:]job]]",
Aliases: []string{"logs"},
Short: "Trace the output of a ci job",
Long: `If a job is not specified the latest running job or last job in the pipeline is used`,
Use: "trace [remote [[branch:]job]]",
Aliases: []string{"logs"},
Short: "Trace the output of a ci job",
Long: `If a job is not specified the latest running job or last job in the pipeline is used`,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
var (
rn string
Expand Down
1 change: 1 addition & 0 deletions cmd/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var cloneCmd = &cobra.Command{
- repo
- namespace/repo
- namespace/group/repo`,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
project, err := gitlab.FindProject(args[0])
if err == gitlab.ErrProjectNotFound {
Expand Down
9 changes: 5 additions & 4 deletions cmd/fork.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ var skipClone = false

// forkCmd represents the fork command
var forkCmd = &cobra.Command{
Use: "fork [upstream-to-fork]",
Short: "Fork a remote repository on GitLab and add as remote",
Long: ``,
Args: cobra.MaximumNArgs(1),
Use: "fork [upstream-to-fork]",
Short: "Fork a remote repository on GitLab and add as remote",
Long: ``,
Args: cobra.MaximumNArgs(1),
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
skipClone, _ = cmd.Flags().GetBool("skip-clone")
if len(args) == 1 {
Expand Down
7 changes: 4 additions & 3 deletions cmd/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
)

var issueCmd = &cobra.Command{
Use: "issue",
Short: `Describe, list, and create issues`,
Long: ``,
Use: "issue",
Short: `Describe, list, and create issues`,
Long: ``,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
if list, _ := cmd.Flags().GetBool("list"); list {
issueListCmd.Run(cmd, args)
Expand Down
9 changes: 5 additions & 4 deletions cmd/issue_browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ import (
var browse = browser.Open

var issueBrowseCmd = &cobra.Command{
Use: "browse [remote] <id>",
Aliases: []string{"b"},
Short: "View issue in a browser",
Long: ``,
Use: "browse [remote] <id>",
Aliases: []string{"b"},
Short: "View issue in a browser",
Long: ``,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, num, err := parseArgs(args)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions cmd/issue_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
)

var issueCloseCmd = &cobra.Command{
Use: "close [remote] <id>",
Aliases: []string{"delete"},
Short: "Close issue by id",
Long: ``,
Args: cobra.MinimumNArgs(1),
Use: "close [remote] <id>",
Aliases: []string{"delete"},
Short: "Close issue by id",
Long: ``,
Args: cobra.MinimumNArgs(1),
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, id, err := parseArgs(args)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions cmd/issue_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (
)

var issueCreateCmd = &cobra.Command{
Use: "create [remote]",
Aliases: []string{"new"},
Short: "Open an issue on GitLab",
Long: ``,
Args: cobra.MaximumNArgs(1),
Use: "create [remote]",
Aliases: []string{"new"},
Short: "Open an issue on GitLab",
Long: ``,
Args: cobra.MaximumNArgs(1),
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
msgs, err := cmd.Flags().GetStringArray("message")
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion cmd/issue_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ lab issue update <id> # same as above
lab issue edit <id> -m "new title" # update title
lab issue edit <id> -m "new title" -m "new desc" # update title & description
lab issue edit <id> -l newlabel --unlabel oldlabel # relabel issue`,
Args: cobra.MinimumNArgs(1),
Args: cobra.MinimumNArgs(1),
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
// get remote and issue from cmd arguments
rn, issueNum, err := parseArgs(args)
Expand Down
1 change: 1 addition & 0 deletions cmd/issue_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var issueListCmd = &cobra.Command{
lab issue list "search terms" # search issues for "search terms"
lab issue search "search terms" # same as above
lab issue list remote "search terms" # search "remote" for issues with "search terms"`,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
issues, err := issueList(args)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions cmd/issue_note.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ import (
)

var issueCreateNoteCmd = &cobra.Command{
Use: "note [remote] <id>",
Aliases: []string{"comment"},
Short: "Add a note or comment to an issue on GitLab",
Long: ``,
Args: cobra.MinimumNArgs(1),
Use: "note [remote] <id>",
Aliases: []string{"comment"},
Short: "Add a note or comment to an issue on GitLab",
Long: ``,
Args: cobra.MinimumNArgs(1),
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, issueNum, err := parseArgs(args)
if err != nil {
Expand Down
16 changes: 6 additions & 10 deletions cmd/issue_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ import (
)

var issueShowCmd = &cobra.Command{
Use: "show [remote] <id>",
Aliases: []string{"get"},
ArgAliases: []string{"s"},
Short: "Describe an issue",
Long: ``,
Use: "show [remote] <id>",
Aliases: []string{"get"},
ArgAliases: []string{"s"},
Short: "Describe an issue",
Long: ``,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {

setCommandPrefix()

rn, issueNum, err := parseArgs(args)
if err != nil {
log.Fatal(err)
Expand All @@ -46,9 +45,6 @@ var issueShowCmd = &cobra.Command{
printIssue(issue, rn, renderMarkdown)

showComments, _ := cmd.Flags().GetBool("comments")
if showComments == false {
showComments = getMainConfig().GetBool(CommandPrefix + "comments")
}
if showComments {
discussions, err := lab.IssueListDiscussions(rn, int(issueNum))
if err != nil {
Expand Down
7 changes: 4 additions & 3 deletions cmd/label.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
)

var labelCmd = &cobra.Command{
Use: "label",
Short: `List and search labels`,
Long: ``,
Use: "label",
Short: `List and search labels`,
Long: ``,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
cmd.Help()
return
Expand Down
1 change: 1 addition & 0 deletions cmd/label_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var labelListCmd = &cobra.Command{
lab label list "search term" # search labels for "search term"
lab label search "search term" # same as above
lab label list remote "search term" # search "remote" for labels with "search term"`,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, labelSearch, err := parseArgsRemoteString(args)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions cmd/merge_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
)

var mergeRequestCmd = &cobra.Command{
Use: "merge-request [remote [branch]]",
Short: mrCreateCmd.Short,
Long: mrCreateCmd.Long,
Args: mrCreateCmd.Args,
Use: "merge-request [remote [branch]]",
Short: mrCreateCmd.Short,
Long: mrCreateCmd.Long,
Args: mrCreateCmd.Args,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
runMRCreate(cmd, args)
},
Expand Down
7 changes: 4 additions & 3 deletions cmd/mr.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (

// mrCmd represents the mr command
var mrCmd = &cobra.Command{
Use: "mr",
Short: `Describe, list, and create merge requests`,
Long: ``,
Use: "mr",
Short: `Describe, list, and create merge requests`,
Long: ``,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
if list, _ := cmd.Flags().GetBool("list"); list {
listCmd.Run(cmd, args)
Expand Down
11 changes: 6 additions & 5 deletions cmd/mr_approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
)

var mrApproveCmd = &cobra.Command{
Use: "approve [remote] <id>",
Aliases: []string{},
Short: "Approve merge request",
Long: ``,
Args: cobra.MinimumNArgs(1),
Use: "approve [remote] <id>",
Aliases: []string{},
Short: "Approve merge request",
Long: ``,
Args: cobra.MinimumNArgs(1),
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, id, err := parseArgs(args)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions cmd/mr_browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ import (
)

var mrBrowseCmd = &cobra.Command{
Use: "browse [remote] <id>",
Aliases: []string{"b"},
Short: "View merge request in a browser",
Long: ``,
Use: "browse [remote] <id>",
Aliases: []string{"b"},
Short: "View merge request in a browser",
Long: ``,
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, num, err := parseArgs(args)
if err != nil {
Expand Down
9 changes: 5 additions & 4 deletions cmd/mr_checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ var (

// listCmd represents the list command
var checkoutCmd = &cobra.Command{
Use: "checkout <id>",
Short: "Checkout an open merge request",
Long: ``,
Args: cobra.MinimumNArgs(1),
Use: "checkout <id>",
Short: "Checkout an open merge request",
Long: ``,
Args: cobra.MinimumNArgs(1),
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, mrID, err := parseArgs(args)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions cmd/mr_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ import (
)

var mrCloseCmd = &cobra.Command{
Use: "close [remote] <id>",
Aliases: []string{"delete"},
Short: "Close merge request",
Long: ``,
Args: cobra.MinimumNArgs(1),
Use: "close [remote] <id>",
Aliases: []string{"delete"},
Short: "Close merge request",
Long: ``,
Args: cobra.MinimumNArgs(1),
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, id, err := parseArgs(args)
if err != nil {
Expand Down
13 changes: 7 additions & 6 deletions cmd/mr_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (

// mrCmd represents the mr command
var mrCreateCmd = &cobra.Command{
Use: "create [remote [branch]]",
Aliases: []string{"new"},
Short: "Open a merge request on GitLab",
Long: `Creates a merge request (default: MR created on default branch of origin)`,
Args: cobra.MaximumNArgs(2),
Run: runMRCreate,
Use: "create [remote [branch]]",
Aliases: []string{"new"},
Short: "Open a merge request on GitLab",
Long: `Creates a merge request (default: MR created on default branch of origin)`,
Args: cobra.MaximumNArgs(2),
PersistentPreRun: LabPersistentPreRun,
Run: runMRCreate,
}

func init() {
Expand Down
11 changes: 6 additions & 5 deletions cmd/mr_discussion.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ import (
)

var mrCreateDiscussionCmd = &cobra.Command{
Use: "discussion [remote] <id>",
Aliases: []string{"comment"},
Short: "Start a discussion on an MR on GitLab",
Long: ``,
Args: cobra.MinimumNArgs(1),
Use: "discussion [remote] <id>",
Aliases: []string{"comment"},
Short: "Start a discussion on an MR on GitLab",
Long: ``,
Args: cobra.MinimumNArgs(1),
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
rn, mrNum, err := parseArgs(args)
if err != nil {
Expand Down
11 changes: 6 additions & 5 deletions cmd/mr_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ var (

// listCmd represents the list command
var listCmd = &cobra.Command{
Use: "list [remote]",
Aliases: []string{"ls"},
Short: "List merge requests",
Long: ``,
Args: cobra.MaximumNArgs(1),
Use: "list [remote]",
Aliases: []string{"ls"},
Short: "List merge requests",
Long: ``,
Args: cobra.MaximumNArgs(1),
PersistentPreRun: LabPersistentPreRun,
Run: func(cmd *cobra.Command, args []string) {
mrs, err := mrList(args)
if err != nil {
Expand Down
Loading

0 comments on commit 97ffd5e

Please sign in to comment.