Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cobra zsh gen #313

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/ci_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
gitlab "github.com/xanzy/go-gitlab"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

// ciCreateCmd represents the run command
Expand Down Expand Up @@ -131,11 +132,11 @@ func parseCIVariables(vars []string) (map[string]string, error) {
}

func init() {
ciCreateCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote_branches origin")
zsh.Wrap(ciCreateCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote_branches origin")
ciCreateCmd.Flags().StringP("project", "p", "", "Project to create pipeline on")
ciCmd.AddCommand(ciCreateCmd)

ciTriggerCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote_branches")
zsh.Wrap(ciTriggerCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote_branches")
ciTriggerCmd.Flags().StringP("project", "p", "", "Project to run pipeline trigger on")
ciTriggerCmd.Flags().StringP("token", "t", os.Getenv("CI_JOB_TOKEN"), "Pipeline trigger token, optional if run within GitLabCI")
ciTriggerCmd.Flags().StringSliceP("variable", "v", []string{}, "Variables to pass to pipeline")
Expand Down
3 changes: 2 additions & 1 deletion cmd/ci_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

// ciStatusCmd represents the run command
Expand Down Expand Up @@ -84,7 +85,7 @@ lab ci status --wait`,
}

func init() {
ciStatusCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote_branches")
zsh.Wrap(ciStatusCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote_branches")
ciStatusCmd.Flags().Bool("wait", false, "Continuously print the status and wait to exit until the pipeline finishes. Exit code indicates pipeline status")
ciCmd.AddCommand(ciStatusCmd)
}
5 changes: 3 additions & 2 deletions cmd/ci_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/spf13/cobra"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

// ciLintCmd represents the lint command
Expand Down Expand Up @@ -108,7 +109,7 @@ func doTrace(ctx context.Context, w io.Writer, pid interface{}, branch, name str
}

func init() {
ciTraceCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
ciTraceCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_remote_branches $words[2]")
zsh.Wrap(ciTraceCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(ciTraceCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_remote_branches $words[2]")
ciCmd.AddCommand(ciTraceCmd)
}
5 changes: 3 additions & 2 deletions cmd/ci_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var (
Expand Down Expand Up @@ -625,7 +626,7 @@ func latestJobs(jobs []*gitlab.Job) []*gitlab.Job {
}

func init() {
ciViewCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
ciViewCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_remote_branches $words[2]")
zsh.Wrap(ciViewCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(ciViewCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_remote_branches $words[2]")
ciCmd.AddCommand(ciViewCmd)
}
5 changes: 4 additions & 1 deletion cmd/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"

"github.com/spf13/cobra"
zsh "github.com/rsteube/cobra-zsh-gen"
)

// completionCmd represents the completion command
Expand All @@ -18,7 +19,9 @@ var completionCmd = &cobra.Command{
case "bash":
RootCmd.GenBashCompletion(os.Stdout)
case "zsh":
RootCmd.GenZshCompletion(os.Stdout)
// currently using BashCompletionFunction variable for additional custom completions in zsh
RootCmd.BashCompletionFunction = zshCompletionFunction
zsh.Wrap(RootCmd).GenZshCompletion(os.Stdout)
default:
println("only 'bash' or 'zsh' allowed")
}
Expand Down
5 changes: 3 additions & 2 deletions cmd/issue_browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
"github.com/zaquestion/lab/internal/browser"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var browse = browser.Open
Expand Down Expand Up @@ -45,7 +46,7 @@ var issueBrowseCmd = &cobra.Command{
}

func init() {
issueBrowseCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
issueBrowseCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
zsh.Wrap(issueBrowseCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(issueBrowseCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
issueCmd.AddCommand(issueBrowseCmd)
}
5 changes: 3 additions & 2 deletions cmd/issue_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var issueCloseCmd = &cobra.Command{
Expand Down Expand Up @@ -34,7 +35,7 @@ var issueCloseCmd = &cobra.Command{
}

func init() {
issueCloseCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
issueCloseCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
zsh.Wrap(issueCloseCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(issueCloseCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
issueCmd.AddCommand(issueCloseCmd)
}
3 changes: 2 additions & 1 deletion cmd/issue_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
gitlab "github.com/xanzy/go-gitlab"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var issueCreateCmd = &cobra.Command{
Expand Down Expand Up @@ -129,6 +130,6 @@ func init() {
issueCreateCmd.Flags().StringSliceP("label", "l", []string{}, "Set the given label(s) on the created issue")
issueCreateCmd.Flags().StringSliceP("assignees", "a", []string{}, "Set assignees by username")

issueCreateCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(issueCreateCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
issueCmd.AddCommand(issueCreateCmd)
}
5 changes: 3 additions & 2 deletions cmd/issue_edit.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
gitlab "github.com/xanzy/go-gitlab"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var issueEditCmd = &cobra.Command{
Expand Down Expand Up @@ -281,7 +282,7 @@ func issueEditCmdAddFlags(flags *pflag.FlagSet) *pflag.FlagSet {

func init() {
issueEditCmdAddFlags(issueEditCmd.Flags())
issueEditCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
issueEditCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
zsh.Wrap(issueEditCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(issueEditCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
issueCmd.AddCommand(issueEditCmd)
}
3 changes: 2 additions & 1 deletion cmd/issue_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra"
gitlab "github.com/xanzy/go-gitlab"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var (
Expand Down Expand Up @@ -73,7 +74,7 @@ func init() {
&issueAll, "all", "a", false,
"List all issues on the project")

issueListCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(issueListCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
issueListCmd.MarkFlagCustom("state", "(opened closed)")
issueCmd.AddCommand(issueListCmd)
}
5 changes: 3 additions & 2 deletions cmd/issue_note.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
gitlab "github.com/xanzy/go-gitlab"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var issueCreateNoteCmd = &cobra.Command{
Expand Down Expand Up @@ -96,7 +97,7 @@ func noteText() (string, error) {
func init() {
issueCreateNoteCmd.Flags().StringSliceP("message", "m", []string{}, "Use the given <msg>; multiple -m are concatenated as separate paragraphs")

issueCreateNoteCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
issueCreateNoteCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
zsh.Wrap(issueCreateNoteCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(issueCreateNoteCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
issueCmd.AddCommand(issueCreateNoteCmd)
}
7 changes: 4 additions & 3 deletions cmd/issue_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/spf13/cobra"
gitlab "github.com/xanzy/go-gitlab"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var issueShowCmd = &cobra.Command{
Expand Down Expand Up @@ -130,9 +131,9 @@ func printDiscussions(discussions []*gitlab.Discussion) {
}

func init() {
issueShowCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
issueShowCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
issueShowCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_issue")
zsh.Wrap(issueShowCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(issueShowCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
zsh.Wrap(issueShowCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_issue")
issueShowCmd.Flags().BoolP("comments", "c", false, "Show comments for the issue")
issueCmd.AddCommand(issueShowCmd)
}
5 changes: 3 additions & 2 deletions cmd/mr_approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var mrApproveCmd = &cobra.Command{
Expand Down Expand Up @@ -34,7 +35,7 @@ var mrApproveCmd = &cobra.Command{
}

func init() {
mrApproveCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
mrApproveCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
zsh.Wrap(mrApproveCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(mrApproveCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
mrCmd.AddCommand(mrApproveCmd)
}
5 changes: 3 additions & 2 deletions cmd/mr_browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
gitlab "github.com/xanzy/go-gitlab"
git "github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var mrBrowseCmd = &cobra.Command{
Expand Down Expand Up @@ -62,7 +63,7 @@ var mrBrowseCmd = &cobra.Command{
}

func init() {
mrBrowseCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
mrBrowseCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
zsh.Wrap(mrBrowseCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(mrBrowseCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
mrCmd.AddCommand(mrBrowseCmd)
}
3 changes: 2 additions & 1 deletion cmd/mr_checkout.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
gitlab "github.com/xanzy/go-gitlab"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

// mrCheckoutConfig holds configuration values for calls to lab mr checkout
Expand Down Expand Up @@ -92,7 +93,7 @@ var checkoutCmd = &cobra.Command{
}

func init() {
checkoutCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_merge_request origin")
zsh.Wrap(checkoutCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_merge_request origin")

checkoutCmd.Flags().StringVarP(&mrCheckoutCfg.branch, "branch", "b", "", "checkout merge request with <branch> name")
checkoutCmd.Flags().BoolVarP(&mrCheckoutCfg.track, "track", "t", false, "set checked out branch to track mr author remote branch, adds remote if needed")
Expand Down
5 changes: 3 additions & 2 deletions cmd/mr_close.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/spf13/cobra"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var mrCloseCmd = &cobra.Command{
Expand Down Expand Up @@ -34,7 +35,7 @@ var mrCloseCmd = &cobra.Command{
}

func init() {
mrCloseCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
mrCloseCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
zsh.Wrap(mrCloseCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(mrCloseCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
mrCmd.AddCommand(mrCloseCmd)
}
5 changes: 3 additions & 2 deletions cmd/mr_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
gitlab "github.com/xanzy/go-gitlab"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

// mrCmd represents the mr command
Expand All @@ -39,8 +40,8 @@ func init() {
mrCreateCmd.Flags().Int("milestone", -1, "Set milestone by milestone ID")
mergeRequestCmd.Flags().AddFlagSet(mrCreateCmd.Flags())

mrCreateCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
mrCreateCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_remote_branches $words[2]")
zsh.Wrap(mrCreateCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(mrCreateCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_remote_branches $words[2]")
mrCmd.AddCommand(mrCreateCmd)
}

Expand Down
3 changes: 2 additions & 1 deletion cmd/mr_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra"
gitlab "github.com/xanzy/go-gitlab"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var (
Expand Down Expand Up @@ -66,7 +67,7 @@ func init() {
"filter merge requests by target branch")
listCmd.Flags().BoolVarP(&mrAll, "all", "a", false, "List all MRs on the project")

listCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(listCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
listCmd.MarkFlagCustom("state", "(opened closed merged)")
mrCmd.AddCommand(listCmd)
}
5 changes: 3 additions & 2 deletions cmd/mr_merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var mrMergeCmd = &cobra.Command{
Expand Down Expand Up @@ -32,7 +33,7 @@ var mrMergeCmd = &cobra.Command{
}

func init() {
mrMergeCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
mrMergeCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
zsh.Wrap(mrMergeCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(mrMergeCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
mrCmd.AddCommand(mrMergeCmd)
}
5 changes: 3 additions & 2 deletions cmd/mr_note.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
gitlab "github.com/xanzy/go-gitlab"
"github.com/zaquestion/lab/internal/git"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var mrCreateNoteCmd = &cobra.Command{
Expand Down Expand Up @@ -96,7 +97,7 @@ func mrNoteText() (string, error) {
func init() {
mrCreateNoteCmd.Flags().StringSliceP("message", "m", []string{}, "Use the given <msg>; multiple -m are concatenated as separate paragraphs")

mrCreateNoteCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
mrCreateNoteCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
zsh.Wrap(mrCreateNoteCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(mrCreateNoteCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_issue $words[2]")
mrCmd.AddCommand(mrCreateNoteCmd)
}
5 changes: 3 additions & 2 deletions cmd/mr_rebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/spf13/cobra"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var mrRebaseCmd = &cobra.Command{
Expand All @@ -31,7 +32,7 @@ var mrRebaseCmd = &cobra.Command{
}

func init() {
mrRebaseCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
mrRebaseCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
zsh.Wrap(mrRebaseCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(mrRebaseCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
mrCmd.AddCommand(mrRebaseCmd)
}
5 changes: 3 additions & 2 deletions cmd/mr_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/spf13/cobra"
gitlab "github.com/xanzy/go-gitlab"
lab "github.com/zaquestion/lab/internal/gitlab"
zsh "github.com/rsteube/cobra-zsh-gen"
)

var mrShowCmd = &cobra.Command{
Expand Down Expand Up @@ -70,7 +71,7 @@ WebURL: %s
}

func init() {
mrShowCmd.MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
mrShowCmd.MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
zsh.Wrap(mrShowCmd).MarkZshCompPositionalArgumentCustom(1, "__lab_completion_remote")
zsh.Wrap(mrShowCmd).MarkZshCompPositionalArgumentCustom(2, "__lab_completion_merge_request $words[2]")
mrCmd.AddCommand(mrShowCmd)
}