From 3d85b6d577bc8a9b2b5517cffeda258690c1e747 Mon Sep 17 00:00:00 2001 From: rsteube Date: Mon, 31 May 2021 22:20:15 +0200 Subject: [PATCH] added glab --- completers/glab_completer/cmd/action/alias.go | 35 +++++++++ completers/glab_completer/cmd/action/api.go | 50 +++++++++++++ .../glab_completer/cmd/action/branch.go | 30 ++++++++ .../glab_completer/cmd/action/config.go | 73 +++++++++++++++++++ .../glab_completer/cmd/action/environment.go | 24 ++++++ completers/glab_completer/cmd/action/group.go | 48 ++++++++++++ completers/glab_completer/cmd/action/issue.go | 33 +++++++++ completers/glab_completer/cmd/action/label.go | 27 +++++++ .../glab_completer/cmd/action/mergeRequest.go | 41 +++++++++++ .../glab_completer/cmd/action/milestone.go | 24 ++++++ .../glab_completer/cmd/action/pipeline.go | 40 ++++++++++ .../glab_completer/cmd/action/project.go | 42 +++++++++++ .../glab_completer/cmd/action/repoOverride.go | 52 +++++++++++++ completers/glab_completer/cmd/action/tag.go | 28 +++++++ completers/glab_completer/cmd/action/user.go | 58 +++++++++++++++ .../glab_completer/cmd/action/utils/utils.go | 51 +++++++++++++ .../glab_completer/cmd/action/variable.go | 24 ++++++ completers/glab_completer/cmd/alias.go | 15 ++++ completers/glab_completer/cmd/alias_delete.go | 21 ++++++ completers/glab_completer/cmd/alias_list.go | 15 ++++ completers/glab_completer/cmd/alias_set.go | 22 ++++++ completers/glab_completer/cmd/api.go | 45 ++++++++++++ completers/glab_completer/cmd/auth.go | 15 ++++ completers/glab_completer/cmd/auth_login.go | 24 ++++++ completers/glab_completer/cmd/auth_status.go | 23 ++++++ completers/glab_completer/cmd/checkUpdate.go | 15 ++++ completers/glab_completer/cmd/ci.go | 22 ++++++ completers/glab_completer/cmd/ci_delete.go | 28 +++++++ completers/glab_completer/cmd/ci_lint.go | 20 +++++ completers/glab_completer/cmd/ci_list.go | 27 +++++++ completers/glab_completer/cmd/ci_run.go | 23 ++++++ completers/glab_completer/cmd/ci_status.go | 24 ++++++ completers/glab_completer/cmd/ci_trace.go | 22 ++++++ completers/glab_completer/cmd/ci_view.go | 22 ++++++ completers/glab_completer/cmd/completion.go | 21 ++++++ completers/glab_completer/cmd/config.go | 16 ++++ completers/glab_completer/cmd/config_get.go | 27 +++++++ completers/glab_completer/cmd/config_init.go | 15 ++++ completers/glab_completer/cmd/config_set.go | 30 ++++++++ completers/glab_completer/cmd/help.go | 15 ++++ completers/glab_completer/cmd/issue.go | 22 ++++++ completers/glab_completer/cmd/issue_board.go | 15 ++++ .../glab_completer/cmd/issue_board_create.go | 16 ++++ .../glab_completer/cmd/issue_board_view.go | 15 ++++ completers/glab_completer/cmd/issue_close.go | 21 ++++++ completers/glab_completer/cmd/issue_create.go | 46 ++++++++++++ completers/glab_completer/cmd/issue_delete.go | 21 ++++++ completers/glab_completer/cmd/issue_list.go | 54 ++++++++++++++ completers/glab_completer/cmd/issue_note.go | 22 ++++++ completers/glab_completer/cmd/issue_reopen.go | 21 ++++++ .../glab_completer/cmd/issue_subscribe.go | 21 ++++++ .../glab_completer/cmd/issue_unsubscribe.go | 21 ++++++ completers/glab_completer/cmd/issue_update.go | 45 ++++++++++++ completers/glab_completer/cmd/issue_view.go | 26 +++++++ completers/glab_completer/cmd/label.go | 22 ++++++ completers/glab_completer/cmd/label_create.go | 24 ++++++ completers/glab_completer/cmd/label_list.go | 17 +++++ completers/glab_completer/cmd/mr.go | 22 ++++++ completers/glab_completer/cmd/mr_approve.go | 22 ++++++ completers/glab_completer/cmd/mr_approvers.go | 21 ++++++ completers/glab_completer/cmd/mr_checkout.go | 29 ++++++++ completers/glab_completer/cmd/mr_close.go | 21 ++++++ completers/glab_completer/cmd/mr_create.go | 48 ++++++++++++ completers/glab_completer/cmd/mr_delete.go | 21 ++++++ completers/glab_completer/cmd/mr_diff.go | 26 +++++++ completers/glab_completer/cmd/mr_for.go | 38 ++++++++++ completers/glab_completer/cmd/mr_issues.go | 21 ++++++ completers/glab_completer/cmd/mr_list.go | 53 ++++++++++++++ completers/glab_completer/cmd/mr_merge.go | 29 ++++++++ completers/glab_completer/cmd/mr_note.go | 22 ++++++ completers/glab_completer/cmd/mr_rebase.go | 21 ++++++ completers/glab_completer/cmd/mr_reopen.go | 21 ++++++ completers/glab_completer/cmd/mr_revoke.go | 21 ++++++ completers/glab_completer/cmd/mr_subscribe.go | 21 ++++++ completers/glab_completer/cmd/mr_todo.go | 21 ++++++ .../glab_completer/cmd/mr_unsubscribe.go | 21 ++++++ completers/glab_completer/cmd/mr_update.go | 53 ++++++++++++++ completers/glab_completer/cmd/mr_view.go | 26 +++++++ completers/glab_completer/cmd/release.go | 22 ++++++ completers/glab_completer/cmd/release_list.go | 22 ++++++ completers/glab_completer/cmd/repo.go | 15 ++++ completers/glab_completer/cmd/repo_archive.go | 33 +++++++++ completers/glab_completer/cmd/repo_clone.go | 36 +++++++++ .../glab_completer/cmd/repo_contributors.go | 28 +++++++ completers/glab_completer/cmd/repo_create.go | 34 +++++++++ completers/glab_completer/cmd/repo_delete.go | 22 ++++++ completers/glab_completer/cmd/repo_fork.go | 27 +++++++ completers/glab_completer/cmd/repo_search.go | 18 +++++ completers/glab_completer/cmd/root.go | 23 ++++++ completers/glab_completer/cmd/user.go | 15 ++++ completers/glab_completer/cmd/user_events.go | 16 ++++ completers/glab_completer/cmd/variable.go | 22 ++++++ completers/glab_completer/cmd/variable_set.go | 37 ++++++++++ completers/glab_completer/cmd/version.go | 15 ++++ completers/glab_completer/main.go | 7 ++ 95 files changed, 2586 insertions(+) create mode 100644 completers/glab_completer/cmd/action/alias.go create mode 100644 completers/glab_completer/cmd/action/api.go create mode 100644 completers/glab_completer/cmd/action/branch.go create mode 100644 completers/glab_completer/cmd/action/config.go create mode 100644 completers/glab_completer/cmd/action/environment.go create mode 100644 completers/glab_completer/cmd/action/group.go create mode 100644 completers/glab_completer/cmd/action/issue.go create mode 100644 completers/glab_completer/cmd/action/label.go create mode 100644 completers/glab_completer/cmd/action/mergeRequest.go create mode 100644 completers/glab_completer/cmd/action/milestone.go create mode 100644 completers/glab_completer/cmd/action/pipeline.go create mode 100644 completers/glab_completer/cmd/action/project.go create mode 100644 completers/glab_completer/cmd/action/repoOverride.go create mode 100644 completers/glab_completer/cmd/action/tag.go create mode 100644 completers/glab_completer/cmd/action/user.go create mode 100644 completers/glab_completer/cmd/action/utils/utils.go create mode 100644 completers/glab_completer/cmd/action/variable.go create mode 100644 completers/glab_completer/cmd/alias.go create mode 100644 completers/glab_completer/cmd/alias_delete.go create mode 100644 completers/glab_completer/cmd/alias_list.go create mode 100644 completers/glab_completer/cmd/alias_set.go create mode 100644 completers/glab_completer/cmd/api.go create mode 100644 completers/glab_completer/cmd/auth.go create mode 100644 completers/glab_completer/cmd/auth_login.go create mode 100644 completers/glab_completer/cmd/auth_status.go create mode 100644 completers/glab_completer/cmd/checkUpdate.go create mode 100644 completers/glab_completer/cmd/ci.go create mode 100644 completers/glab_completer/cmd/ci_delete.go create mode 100644 completers/glab_completer/cmd/ci_lint.go create mode 100644 completers/glab_completer/cmd/ci_list.go create mode 100644 completers/glab_completer/cmd/ci_run.go create mode 100644 completers/glab_completer/cmd/ci_status.go create mode 100644 completers/glab_completer/cmd/ci_trace.go create mode 100644 completers/glab_completer/cmd/ci_view.go create mode 100644 completers/glab_completer/cmd/completion.go create mode 100644 completers/glab_completer/cmd/config.go create mode 100644 completers/glab_completer/cmd/config_get.go create mode 100644 completers/glab_completer/cmd/config_init.go create mode 100644 completers/glab_completer/cmd/config_set.go create mode 100644 completers/glab_completer/cmd/help.go create mode 100644 completers/glab_completer/cmd/issue.go create mode 100644 completers/glab_completer/cmd/issue_board.go create mode 100644 completers/glab_completer/cmd/issue_board_create.go create mode 100644 completers/glab_completer/cmd/issue_board_view.go create mode 100644 completers/glab_completer/cmd/issue_close.go create mode 100644 completers/glab_completer/cmd/issue_create.go create mode 100644 completers/glab_completer/cmd/issue_delete.go create mode 100644 completers/glab_completer/cmd/issue_list.go create mode 100644 completers/glab_completer/cmd/issue_note.go create mode 100644 completers/glab_completer/cmd/issue_reopen.go create mode 100644 completers/glab_completer/cmd/issue_subscribe.go create mode 100644 completers/glab_completer/cmd/issue_unsubscribe.go create mode 100644 completers/glab_completer/cmd/issue_update.go create mode 100644 completers/glab_completer/cmd/issue_view.go create mode 100644 completers/glab_completer/cmd/label.go create mode 100644 completers/glab_completer/cmd/label_create.go create mode 100644 completers/glab_completer/cmd/label_list.go create mode 100644 completers/glab_completer/cmd/mr.go create mode 100644 completers/glab_completer/cmd/mr_approve.go create mode 100644 completers/glab_completer/cmd/mr_approvers.go create mode 100644 completers/glab_completer/cmd/mr_checkout.go create mode 100644 completers/glab_completer/cmd/mr_close.go create mode 100644 completers/glab_completer/cmd/mr_create.go create mode 100644 completers/glab_completer/cmd/mr_delete.go create mode 100644 completers/glab_completer/cmd/mr_diff.go create mode 100644 completers/glab_completer/cmd/mr_for.go create mode 100644 completers/glab_completer/cmd/mr_issues.go create mode 100644 completers/glab_completer/cmd/mr_list.go create mode 100644 completers/glab_completer/cmd/mr_merge.go create mode 100644 completers/glab_completer/cmd/mr_note.go create mode 100644 completers/glab_completer/cmd/mr_rebase.go create mode 100644 completers/glab_completer/cmd/mr_reopen.go create mode 100644 completers/glab_completer/cmd/mr_revoke.go create mode 100644 completers/glab_completer/cmd/mr_subscribe.go create mode 100644 completers/glab_completer/cmd/mr_todo.go create mode 100644 completers/glab_completer/cmd/mr_unsubscribe.go create mode 100644 completers/glab_completer/cmd/mr_update.go create mode 100644 completers/glab_completer/cmd/mr_view.go create mode 100644 completers/glab_completer/cmd/release.go create mode 100644 completers/glab_completer/cmd/release_list.go create mode 100644 completers/glab_completer/cmd/repo.go create mode 100644 completers/glab_completer/cmd/repo_archive.go create mode 100644 completers/glab_completer/cmd/repo_clone.go create mode 100644 completers/glab_completer/cmd/repo_contributors.go create mode 100644 completers/glab_completer/cmd/repo_create.go create mode 100644 completers/glab_completer/cmd/repo_delete.go create mode 100644 completers/glab_completer/cmd/repo_fork.go create mode 100644 completers/glab_completer/cmd/repo_search.go create mode 100644 completers/glab_completer/cmd/root.go create mode 100644 completers/glab_completer/cmd/user.go create mode 100644 completers/glab_completer/cmd/user_events.go create mode 100644 completers/glab_completer/cmd/variable.go create mode 100644 completers/glab_completer/cmd/variable_set.go create mode 100644 completers/glab_completer/cmd/version.go create mode 100644 completers/glab_completer/main.go diff --git a/completers/glab_completer/cmd/action/alias.go b/completers/glab_completer/cmd/action/alias.go new file mode 100644 index 0000000000..9a9ab50599 --- /dev/null +++ b/completers/glab_completer/cmd/action/alias.go @@ -0,0 +1,35 @@ +package action + +import ( + "io/ioutil" + "os" + + "github.com/rsteube/carapace" + "gopkg.in/yaml.v3" +) + +func loadAliases() (aliases map[string]string, err error) { + var dir string + if dir, err = os.UserConfigDir(); err == nil { + var content []byte + if content, err = ioutil.ReadFile(dir + "/glab-cli/aliases.yml"); err == nil { + err = yaml.Unmarshal(content, &aliases) + } + } + return +} + +func ActionAliases() carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + aliases, err := loadAliases() + if err != nil { + return carapace.ActionMessage(err.Error()) + } + + vals := make([]string, 0) + for alias, desc := range aliases { + vals = append(vals, alias, desc) + } + return carapace.ActionValuesDescribed(vals...) + }) +} diff --git a/completers/glab_completer/cmd/action/api.go b/completers/glab_completer/cmd/action/api.go new file mode 100644 index 0000000000..be4de9f27c --- /dev/null +++ b/completers/glab_completer/cmd/action/api.go @@ -0,0 +1,50 @@ +package action + +import ( + "encoding/json" + "fmt" + "net/url" + "strings" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +func actionApi(cmd *cobra.Command, query string, v interface{}, transform func() carapace.Action) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if flag := cmd.Flag("repo"); flag != nil && flag.Changed { + project := strings.Join(strings.Split(flag.Value.String(), "/")[1:], "/") + query = strings.Replace(query, ":fullpath", url.PathEscape(project), 1) + } + + args := []string{"api"} + if flag := cmd.Flag("repo"); flag != nil && flag.Changed { + host := strings.Split(flag.Value.String(), "/")[0] + args = append(args, "--hostname", host) + } + args = append(args, query) + return carapace.ActionExecCommand("glab", args...)(func(output []byte) carapace.Action { + if err := json.Unmarshal(output, &v); err != nil { + return carapace.ActionMessage("failed to unmarshall response: " + err.Error()) + } + return transform() + }) + }) +} + +func actionGraphql(cmd *cobra.Command, query string, v interface{}, transform func() carapace.Action) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + args := []string{"api", "graphql"} + if flag := cmd.Flag("repo"); flag != nil && flag.Changed { + host := strings.Split(flag.Value.String(), "/")[0] + args = append(args, "--hostname", host) + } + args = append(args, "-f", fmt.Sprintf("query=%v", query)) + return carapace.ActionExecCommand("glab", args...)(func(output []byte) carapace.Action { + if err := json.Unmarshal(output, &v); err != nil { + return carapace.ActionMessage("failed to unmarshall response: " + err.Error()) + } + return transform() + }) + }) +} diff --git a/completers/glab_completer/cmd/action/branch.go b/completers/glab_completer/cmd/action/branch.go new file mode 100644 index 0000000000..d2e78cb056 --- /dev/null +++ b/completers/glab_completer/cmd/action/branch.go @@ -0,0 +1,30 @@ +package action + +import ( + "fmt" + "net/url" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type branch struct { + Name string + Commit struct { + Title string + } +} + +func ActionBranches(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + var branches []branch + query := fmt.Sprintf("/projects/:fullpath/repository/branches?search=^%v", url.QueryEscape(c.CallbackValue)) + return actionApi(cmd, query, &branches, func() carapace.Action { + vals := make([]string, 0, len(branches)*2) + for _, branch := range branches { + vals = append(vals, branch.Name, branch.Commit.Title) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/glab_completer/cmd/action/config.go b/completers/glab_completer/cmd/action/config.go new file mode 100644 index 0000000000..659636955f --- /dev/null +++ b/completers/glab_completer/cmd/action/config.go @@ -0,0 +1,73 @@ +package action + +import ( + "io/ioutil" + "os" + + "github.com/rsteube/carapace" + "gopkg.in/yaml.v3" +) + +func ActionConfigHosts() carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if hosts, err := hosts(); err != nil { + return carapace.ActionMessage(err.Error()) + } else { + return carapace.ActionValues(hosts...) + } + }) +} + +type glabConfig struct { + Hosts map[string]interface{} +} + +func hosts() ([]string, error) { + config, err := loadConfig() + if err != nil { + return nil, err + } + + hosts := make([]string, 0) + for host := range config.Hosts { + hosts = append(hosts, host) + } + return hosts, nil +} + +func loadConfig() (config *glabConfig, err error) { + var dir string + if dir, err = os.UserConfigDir(); err == nil { + var content []byte + if content, err = ioutil.ReadFile(dir + "/glab-cli/config.yml"); err == nil { + err = yaml.Unmarshal(content, &config) + } + } + return +} + +func ActionConfigKeys() carapace.Action { + return carapace.ActionValuesDescribed( + "token", "Your gitlab access token, defaults to environment variables", + "gitlab_uri", "if unset, defaults to https://gitlab.com", + "browser", "if unset, defaults to environment variables", + "editor", "if unset, defaults to environment variables.", + "visual", "alternative for editor. if unset, defaults to environment variables.", + "glamour_style", "Your desired markdown renderer style.", + ) +} + +func ActionConfigValues(key string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + actions := map[string]carapace.Action{ + "token": carapace.ActionValues(), + "gitlab_uri": carapace.ActionValues(), + "browser": carapace.ActionFiles(), + "editor": carapace.ActionFiles(), + "visual": carapace.ActionFiles(), + "glamour_style": carapace.ActionValues("dark", "light", "notty"), + } + + return actions[key] + }) +} diff --git a/completers/glab_completer/cmd/action/environment.go b/completers/glab_completer/cmd/action/environment.go new file mode 100644 index 0000000000..730f3af219 --- /dev/null +++ b/completers/glab_completer/cmd/action/environment.go @@ -0,0 +1,24 @@ +package action + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type environment struct { + Name string + ExternalUrl string `json:"external_url"` +} + +func ActionEnvironments(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + var queryResult []environment + return actionApi(cmd, "projects/:fullpath/environments", &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, env := range queryResult { + vals = append(vals, env.Name, env.ExternalUrl) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/glab_completer/cmd/action/group.go b/completers/glab_completer/cmd/action/group.go new file mode 100644 index 0000000000..e5fd680d06 --- /dev/null +++ b/completers/glab_completer/cmd/action/group.go @@ -0,0 +1,48 @@ +package action + +import ( + "fmt" + "net/url" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type group struct { + Path string + Description string +} + +func ActionGroups(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + query := fmt.Sprintf(`groups?all_available=true&search=%v`, url.QueryEscape(c.CallbackValue)) + + var queryResult []group + return actionApi(cmd, query, queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, group := range queryResult { + vals = append(vals, group.Path, group.Description) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} + +func ActionSubgroups(cmd *cobra.Command, groupID string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + query := fmt.Sprintf(`groups/%v/subgroups?all_available=true&search=%v`, url.PathEscape(groupID), url.QueryEscape(c.CallbackValue)) + + var queryResult []group + return actionApi(cmd, query, &queryResult, func() carapace.Action { + // TODO allow failure + // if strings.Contains(err.Error(), "404 Group Not Found") { + // return carapace.ActionValues() // fail silently for repo completion + // } + vals := make([]string, 0, len(queryResult)*2) + for _, group := range queryResult { + vals = append(vals, group.Path, group.Description) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/glab_completer/cmd/action/issue.go b/completers/glab_completer/cmd/action/issue.go new file mode 100644 index 0000000000..369e2ce715 --- /dev/null +++ b/completers/glab_completer/cmd/action/issue.go @@ -0,0 +1,33 @@ +package action + +import ( + "fmt" + "net/url" + "strconv" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type issue struct { + Iid int + Title string +} + +func ActionIssues(cmd *cobra.Command, state string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + stateQuery := "" + if state != "" { + stateQuery = "&state=" + url.QueryEscape(state) + } + + var queryResult []issue + return actionApi(cmd, fmt.Sprintf("projects/:fullpath/issues?order_by=updated_at&per_page=100%v", stateQuery), &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, issue := range queryResult { + vals = append(vals, strconv.Itoa(issue.Iid), issue.Title) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/glab_completer/cmd/action/label.go b/completers/glab_completer/cmd/action/label.go new file mode 100644 index 0000000000..a76f196d05 --- /dev/null +++ b/completers/glab_completer/cmd/action/label.go @@ -0,0 +1,27 @@ +package action + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type label struct { + Name string + Description string +} + +func ActionLabels(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + //repo := "" // TODO from config or var + + var queryResult []label + return actionApi(cmd, "projects/:fullpath/labels", &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, label := range queryResult { + vals = append(vals, label.Name, label.Description) + } + return carapace.ActionValuesDescribed(vals...) + //}).Cache(1*time.Hour, cache.String(repo.FullName())) + }) + }) +} diff --git a/completers/glab_completer/cmd/action/mergeRequest.go b/completers/glab_completer/cmd/action/mergeRequest.go new file mode 100644 index 0000000000..d4a26ca06a --- /dev/null +++ b/completers/glab_completer/cmd/action/mergeRequest.go @@ -0,0 +1,41 @@ +package action + +import ( + "fmt" + "net/url" + "strconv" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type mergeRequest struct { + Iid int + Title string +} + +func ActionMergeRequests(cmd *cobra.Command, state string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + stateQuery := "" + if state != "" { + stateQuery = "&state=" + url.QueryEscape(state) + } + + var queryResult []mergeRequest + return actionApi(cmd, fmt.Sprintf("projects/:fullpath/merge_requests?order_by=updated_at&per_page=100%v", stateQuery), queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, mr := range queryResult { + vals = append(vals, strconv.Itoa(mr.Iid), mr.Title) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} + +func ActionMergeRequestsAndBranches(cmd *cobra.Command, state string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + branches := ActionBranches(cmd).Invoke(c) + mergeRequests := ActionMergeRequests(cmd, state).Invoke(c) + return branches.Merge(mergeRequests).Filter(c.Args).ToA() + }) +} diff --git a/completers/glab_completer/cmd/action/milestone.go b/completers/glab_completer/cmd/action/milestone.go new file mode 100644 index 0000000000..f9a503ddaa --- /dev/null +++ b/completers/glab_completer/cmd/action/milestone.go @@ -0,0 +1,24 @@ +package action + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type milestone struct { + Title string + Description string +} + +func ActionMilestones(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + var queryResult []milestone + return actionApi(cmd, "projects/:fullpath/milestones", &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, milestone := range queryResult { + vals = append(vals, milestone.Title, milestone.Description) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/glab_completer/cmd/action/pipeline.go b/completers/glab_completer/cmd/action/pipeline.go new file mode 100644 index 0000000000..ad406c1011 --- /dev/null +++ b/completers/glab_completer/cmd/action/pipeline.go @@ -0,0 +1,40 @@ +package action + +import ( + "fmt" + "net/url" + "strconv" + "time" + + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action/utils" + "github.com/spf13/cobra" +) + +type pipeline struct { + Id int + Ref string + CreatedAt *time.Time `json:"created_at"` +} + +func ActionPipelines(cmd *cobra.Command, status string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + statusFilter := "" + if status != "" { + statusFilter = "&status=" + url.QueryEscape(status) + } + + var queryResult []pipeline + return actionApi(cmd, fmt.Sprintf("projects/:fullpath/pipelines?order_by=updated_at&per_page=100%v", statusFilter), &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, pipeline := range queryResult { + description := pipeline.Ref + if pipeline.CreatedAt != nil { + description = fmt.Sprintf("%v (%v)", pipeline.Ref, utils.TimeToPrettyTimeAgo(*pipeline.CreatedAt)) + } + vals = append(vals, strconv.Itoa(pipeline.Id), description) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/glab_completer/cmd/action/project.go b/completers/glab_completer/cmd/action/project.go new file mode 100644 index 0000000000..817607b827 --- /dev/null +++ b/completers/glab_completer/cmd/action/project.go @@ -0,0 +1,42 @@ +package action + +import ( + "fmt" + "net/url" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type project struct { + Path string + Description string +} + +func ActionGroupProjects(cmd *cobra.Command, groupID string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + query := fmt.Sprintf(`groups/%v/projects?order_by=updated_at&per_page=100&search=%v`, url.PathEscape(groupID), url.QueryEscape(c.CallbackValue)) + var queryResult []project + return actionApi(cmd, query, &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, project := range queryResult { + vals = append(vals, project.Path, project.Description) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} + +func ActionUserProjects(cmd *cobra.Command, userID string) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + query := fmt.Sprintf(`users/%v/projects?order_by=updated_at&per_page=100&search=%v`, url.PathEscape(userID), url.QueryEscape(c.CallbackValue)) + var queryResult []project + return actionApi(cmd, query, &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, project := range queryResult { + vals = append(vals, project.Path, project.Description) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/glab_completer/cmd/action/repoOverride.go b/completers/glab_completer/cmd/action/repoOverride.go new file mode 100644 index 0000000000..16315059dc --- /dev/null +++ b/completers/glab_completer/cmd/action/repoOverride.go @@ -0,0 +1,52 @@ +package action + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "strings" +) + +func ActionRepo(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + configHosts, err := hosts() + if err != nil { + return carapace.ActionMessage(err.Error()) + } + + if strings.Contains(c.CallbackValue, "/") { + isKnownHost := false + for _, host := range configHosts { + if strings.HasPrefix(c.CallbackValue, host) { + isKnownHost = true + break + } + } + if !isKnownHost { + return carapace.ActionValues() // only complete full host style for simplicity + } + } + + return carapace.ActionMultiParts("/", func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.ActionValues(configHosts...).Invoke(c).Suffix("/").ToA() + case 1: + // TODO goroutine + users := ActionUsers(cmd).Invoke(c).Suffix("/") + groups := ActionGroups(cmd).Invoke(c).Suffix("/") + return users.Merge(groups).ToA() + case 2: + // TODO goroutine + subgroups := ActionSubgroups(cmd, c.Parts[1]).Invoke(c).Suffix("/") + groupProjects := ActionGroupProjects(cmd, c.Parts[1]).Invoke(c) + userProjects := ActionUserProjects(cmd, c.Parts[1]).Invoke(c) + return subgroups.Merge(groupProjects, userProjects).ToA() + case 3: + groupProjects := ActionGroupProjects(cmd, strings.Join(c.Parts[1:], "/")).Invoke(c) + return groupProjects.ToA() + default: + return carapace.ActionValues() + } + }) + }) +} diff --git a/completers/glab_completer/cmd/action/tag.go b/completers/glab_completer/cmd/action/tag.go new file mode 100644 index 0000000000..5451dcbc86 --- /dev/null +++ b/completers/glab_completer/cmd/action/tag.go @@ -0,0 +1,28 @@ +package action + +import ( + "fmt" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type tag struct { + Name string + Commit struct { + Title string + } +} + +func ActionTags(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + var queryResult []tag + return actionApi(cmd, fmt.Sprintf("projects/:fullpath/repository/tags?order_by=updated&per_page=100&search=%v", c.CallbackValue), &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, tag := range queryResult { + vals = append(vals, tag.Name, tag.Commit.Title) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/glab_completer/cmd/action/user.go b/completers/glab_completer/cmd/action/user.go new file mode 100644 index 0000000000..82c20e142a --- /dev/null +++ b/completers/glab_completer/cmd/action/user.go @@ -0,0 +1,58 @@ +package action + +import ( + "fmt" + "net/url" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type user struct { + Username string + Name string +} + +type userQuery struct { + Data struct { + Users struct { + Nodes []user + } + } +} + +func ActionUsers(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if len(c.CallbackValue) < 3 { + return carapace.ActionMessage("search needs at least 3 characters") + } + + query := fmt.Sprintf(`{ users(search: "%v") { nodes { username, name } } }`, c.CallbackValue) + var queryResult userQuery + return actionGraphql(cmd, query, &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult.Data.Users.Nodes)*2) + for _, user := range queryResult.Data.Users.Nodes { + vals = append(vals, user.Username, user.Name) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} + +func ActionProjectMembers(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + if len(c.CallbackValue) < 3 { + return carapace.ActionMessage("search needs at least 3 characters") + } + query := fmt.Sprintf(`/projects/:fullpath/members/all?query=%v`, url.QueryEscape(c.CallbackValue)) + + var queryResult []user + return actionApi(cmd, query, &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, member := range queryResult { + vals = append(vals, member.Username, member.Name) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/glab_completer/cmd/action/utils/utils.go b/completers/glab_completer/cmd/action/utils/utils.go new file mode 100644 index 0000000000..774be3a1a6 --- /dev/null +++ b/completers/glab_completer/cmd/action/utils/utils.go @@ -0,0 +1,51 @@ +package utils + +import ( + "fmt" + "time" +) + +func Pluralize(num int, thing string) string { + if num == 1 { + return fmt.Sprintf("%d %s", num, thing) + } + return fmt.Sprintf("%d %ss", num, thing) +} + +func fmtDuration(amount int, unit string) string { + return fmt.Sprintf("about %s ago", Pluralize(amount, unit)) +} + +func PrettyTimeAgo(ago time.Duration) string { + if ago < time.Minute { + return "less than a minute ago" + } + if ago < time.Hour { + return fmtDuration(int(ago.Minutes()), "minute") + } + if ago < 24*time.Hour { + return fmtDuration(int(ago.Hours()), "hour") + } + if ago < 30*24*time.Hour { + return fmtDuration(int(ago.Hours())/24, "day") + } + if ago < 365*24*time.Hour { + return fmtDuration(int(ago.Hours())/24/30, "month") + } + + return fmtDuration(int(ago.Hours()/24/365), "year") +} + +func TimeToPrettyTimeAgo(d time.Time) string { + now := time.Now() + ago := now.Sub(d) + return PrettyTimeAgo(ago) +} + +func FmtDuration(d time.Duration) string { + d = d.Round(time.Second) + m := d / time.Minute + d -= m * time.Minute + s := d / time.Second + return fmt.Sprintf("%02dm %02ds", m, s) +} diff --git a/completers/glab_completer/cmd/action/variable.go b/completers/glab_completer/cmd/action/variable.go new file mode 100644 index 0000000000..6b1c650a9d --- /dev/null +++ b/completers/glab_completer/cmd/action/variable.go @@ -0,0 +1,24 @@ +package action + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +type variable struct { + Key string + Value string +} + +func ActionVariables(cmd *cobra.Command) carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + var queryResult []variable + return actionApi(cmd, "projects/:fullpath/variables", &queryResult, func() carapace.Action { + vals := make([]string, 0, len(queryResult)*2) + for _, v := range queryResult { + vals = append(vals, v.Key, v.Value) + } + return carapace.ActionValuesDescribed(vals...) + }) + }) +} diff --git a/completers/glab_completer/cmd/alias.go b/completers/glab_completer/cmd/alias.go new file mode 100644 index 0000000000..f47adfdadb --- /dev/null +++ b/completers/glab_completer/cmd/alias.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var aliasCmd = &cobra.Command{ + Use: "alias", + Short: "Create, list and delete aliases", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + rootCmd.AddCommand(aliasCmd) +} diff --git a/completers/glab_completer/cmd/alias_delete.go b/completers/glab_completer/cmd/alias_delete.go new file mode 100644 index 0000000000..305d6bd497 --- /dev/null +++ b/completers/glab_completer/cmd/alias_delete.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var alias_deleteCmd = &cobra.Command{ + Use: "delete", + Short: "Delete an alias.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + aliasCmd.AddCommand(alias_deleteCmd) + + carapace.Gen(alias_deleteCmd).PositionalCompletion( + action.ActionAliases(), + ) +} diff --git a/completers/glab_completer/cmd/alias_list.go b/completers/glab_completer/cmd/alias_list.go new file mode 100644 index 0000000000..56e63334e3 --- /dev/null +++ b/completers/glab_completer/cmd/alias_list.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var alias_listCmd = &cobra.Command{ + Use: "list", + Short: "List the available aliases.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + aliasCmd.AddCommand(alias_listCmd) +} diff --git a/completers/glab_completer/cmd/alias_set.go b/completers/glab_completer/cmd/alias_set.go new file mode 100644 index 0000000000..b2b9c42ac9 --- /dev/null +++ b/completers/glab_completer/cmd/alias_set.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/gh_completer/cmd/action" + "github.com/spf13/cobra" +) + +var alias_setCmd = &cobra.Command{ + Use: "set", + Short: "Set an alias.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + alias_setCmd.Flags().BoolP("shell", "s", false, "Declare an alias to be passed through a shell interpreter") + aliasCmd.AddCommand(alias_setCmd) + + carapace.Gen(alias_setCmd).PositionalCompletion( + action.ActionAliases(), + ) +} diff --git a/completers/glab_completer/cmd/api.go b/completers/glab_completer/cmd/api.go new file mode 100644 index 0000000000..5029adb525 --- /dev/null +++ b/completers/glab_completer/cmd/api.go @@ -0,0 +1,45 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/rsteube/carapace-bin/pkg/actions/net/http" + "github.com/spf13/cobra" +) + +var apiCmd = &cobra.Command{ + Use: "api", + Short: "Make an authenticated request to GitLab API", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + apiCmd.Flags().StringArrayP("field", "F", []string{}, "Add a parameter of inferred type") + apiCmd.Flags().StringArrayP("header", "H", []string{}, "Add an additional HTTP request header") + apiCmd.Flags().String("hostname", "", "The GitLab hostname for the request (default is \"gitlab.com\" or authenticated host in current git directory)") + apiCmd.Flags().BoolP("include", "i", false, "Include HTTP response headers in the output") + apiCmd.Flags().String("input", "", "The file to use as body for the HTTP request") + apiCmd.Flags().StringP("method", "X", "GET", "The HTTP method for the request") + apiCmd.Flags().Bool("paginate", false, "Make additional HTTP requests to fetch all pages of results") + apiCmd.Flags().StringArrayP("raw-field", "f", []string{}, "Add a string parameter") + apiCmd.Flags().Bool("silent", false, "Do not print the response body") + rootCmd.AddCommand(apiCmd) + + carapace.Gen(apiCmd).FlagCompletion(carapace.ActionMap{ + "hostname": action.ActionConfigHosts(), + "input": carapace.ActionFiles(), + "method": http.ActionRequestMethods(), + "header": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return carapace.ActionMultiParts(":", func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return http.ActionHttpRequestHeaderNames().Invoke(c).Suffix(":").ToA() + case 1: + return http.ActionHttpRequestHeaderValues(c.Parts[0]) + default: + return carapace.ActionValues() + } + }) + }), + }) +} diff --git a/completers/glab_completer/cmd/auth.go b/completers/glab_completer/cmd/auth.go new file mode 100644 index 0000000000..2997c371e4 --- /dev/null +++ b/completers/glab_completer/cmd/auth.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var authCmd = &cobra.Command{ + Use: "auth", + Short: "Manage glab's authentication state", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + rootCmd.AddCommand(authCmd) +} diff --git a/completers/glab_completer/cmd/auth_login.go b/completers/glab_completer/cmd/auth_login.go new file mode 100644 index 0000000000..6edea0ae66 --- /dev/null +++ b/completers/glab_completer/cmd/auth_login.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var auth_loginCmd = &cobra.Command{ + Use: "login", + Short: "Authenticate with a GitLab instance", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + auth_loginCmd.Flags().StringP("hostname", "h", "", "The hostname of the GitLab instance to authenticate with") + auth_loginCmd.Flags().Bool("stdin", false, "Read token from standard input") + auth_loginCmd.Flags().StringP("token", "t", "", "Your GitLab access token") + authCmd.AddCommand(auth_loginCmd) + + carapace.Gen(auth_loginCmd).FlagCompletion(carapace.ActionMap{ + "hostname": action.ActionConfigHosts(), + }) +} diff --git a/completers/glab_completer/cmd/auth_status.go b/completers/glab_completer/cmd/auth_status.go new file mode 100644 index 0000000000..528182bcdd --- /dev/null +++ b/completers/glab_completer/cmd/auth_status.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var auth_statusCmd = &cobra.Command{ + Use: "status", + Short: "View authentication status", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + auth_statusCmd.Flags().StringP("hostname", "h", "", "Check a specific instance's authentication status") + auth_statusCmd.Flags().BoolP("show-token", "t", false, "Display the auth token") + authCmd.AddCommand(auth_statusCmd) + + carapace.Gen(auth_statusCmd).FlagCompletion(carapace.ActionMap{ + "hostname": action.ActionConfigHosts(), + }) +} diff --git a/completers/glab_completer/cmd/checkUpdate.go b/completers/glab_completer/cmd/checkUpdate.go new file mode 100644 index 0000000000..95e50cec1e --- /dev/null +++ b/completers/glab_completer/cmd/checkUpdate.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var checkUpdateCmd = &cobra.Command{ + Use: "check-update", + Short: "Check for latest glab releases", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + rootCmd.AddCommand(checkUpdateCmd) +} diff --git a/completers/glab_completer/cmd/ci.go b/completers/glab_completer/cmd/ci.go new file mode 100644 index 0000000000..7eac661d69 --- /dev/null +++ b/completers/glab_completer/cmd/ci.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var ciCmd = &cobra.Command{ + Use: "ci", + Short: "Work with GitLab CI pipelines and jobs", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + ciCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format or full URL or git URL") + rootCmd.AddCommand(ciCmd) + + carapace.Gen(ciCmd).FlagCompletion(carapace.ActionMap{ + "repo": action.ActionRepo(ciCmd), + }) +} diff --git a/completers/glab_completer/cmd/ci_delete.go b/completers/glab_completer/cmd/ci_delete.go new file mode 100644 index 0000000000..1ed4713f96 --- /dev/null +++ b/completers/glab_completer/cmd/ci_delete.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var ci_deleteCmd = &cobra.Command{ + Use: "delete", + Short: "Delete a CI pipeline", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + ci_deleteCmd.Flags().StringP("status", "s", "", "delete pipelines by status: {running|pending|success|failed|canceled|skipped|created|manual}") + ciCmd.AddCommand(ci_deleteCmd) + + carapace.Gen(ci_deleteCmd).FlagCompletion(carapace.ActionMap{ + "status": carapace.ActionValues("running", "pending", "success", "failed", "canceled", "skipped", "created", "manual"), + }) + + carapace.Gen(ci_deleteCmd).PositionalCompletion( + carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionPipelines(ci_deleteCmd, ci_deleteCmd.Flag("status").Value.String()).Invoke(c).Filter(c.Args).ToA() + }), + ) +} diff --git a/completers/glab_completer/cmd/ci_lint.go b/completers/glab_completer/cmd/ci_lint.go new file mode 100644 index 0000000000..0095eb18d8 --- /dev/null +++ b/completers/glab_completer/cmd/ci_lint.go @@ -0,0 +1,20 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var ci_lintCmd = &cobra.Command{ + Use: "lint", + Short: "Checks if your .gitlab-ci.yml file is valid.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + ciCmd.AddCommand(ci_lintCmd) + + carapace.Gen(ci_lintCmd).PositionalCompletion( + carapace.ActionFiles(".gitlab-ci.yml"), + ) +} diff --git a/completers/glab_completer/cmd/ci_list.go b/completers/glab_completer/cmd/ci_list.go new file mode 100644 index 0000000000..89c879aaf7 --- /dev/null +++ b/completers/glab_completer/cmd/ci_list.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var ci_listCmd = &cobra.Command{ + Use: "list", + Short: "Get the list of CI pipelines", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + ci_listCmd.Flags().StringP("orderBy", "o", "", "Order pipeline by ") + ci_listCmd.Flags().IntP("page", "p", 1, "Page number") + ci_listCmd.Flags().IntP("per-page", "P", 30, "Number of items to list per page. (default 30)") + ci_listCmd.Flags().String("sort", "desc", "Sort pipeline by {asc|desc}. (Defaults to desc)") + ci_listCmd.Flags().StringP("status", "s", "", "Get pipeline with status: {running|pending|success|failed|canceled|skipped|created|manual}") + ciCmd.AddCommand(ci_listCmd) + + carapace.Gen(ci_listCmd).FlagCompletion(carapace.ActionMap{ + "orderBy": carapace.ActionValues("id", "status", "ref", "updated_at", "user_id"), + "sort": carapace.ActionValues("asc", "desc"), + "status": carapace.ActionValues("running", "pending", "success", "failed", "canceled", "skipped", "created", "manual"), + }) +} diff --git a/completers/glab_completer/cmd/ci_run.go b/completers/glab_completer/cmd/ci_run.go new file mode 100644 index 0000000000..a5199b0209 --- /dev/null +++ b/completers/glab_completer/cmd/ci_run.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var ci_runCmd = &cobra.Command{ + Use: "run", + Short: "Create or run a new CI pipeline", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + ci_runCmd.Flags().StringP("branch", "b", "", "Create pipeline on branch/ref ") + ci_runCmd.Flags().StringSlice("variables", []string{}, "Pass variables to pipeline") + ciCmd.AddCommand(ci_runCmd) + + carapace.Gen(ci_runCmd).FlagCompletion(carapace.ActionMap{ + "branch": action.ActionBranches(ci_runCmd), + }) +} diff --git a/completers/glab_completer/cmd/ci_status.go b/completers/glab_completer/cmd/ci_status.go new file mode 100644 index 0000000000..9abb51c847 --- /dev/null +++ b/completers/glab_completer/cmd/ci_status.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var ci_statusCmd = &cobra.Command{ + Use: "status", + Short: "View a running CI pipeline on current or other branch specified", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + ci_statusCmd.Flags().StringP("branch", "b", "", "Check pipeline status for a branch. (Default is current branch)") + ci_statusCmd.Flags().BoolP("compact", "c", false, "Show status in compact format") + ci_statusCmd.Flags().BoolP("live", "l", false, "Show status in real-time till pipeline ends") + ciCmd.AddCommand(ci_statusCmd) + + carapace.Gen(ci_statusCmd).FlagCompletion(carapace.ActionMap{ + "branch": action.ActionBranches(ci_statusCmd), + }) +} diff --git a/completers/glab_completer/cmd/ci_trace.go b/completers/glab_completer/cmd/ci_trace.go new file mode 100644 index 0000000000..900ef8a6d2 --- /dev/null +++ b/completers/glab_completer/cmd/ci_trace.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var ci_traceCmd = &cobra.Command{ + Use: "trace", + Short: "Trace a CI job log in real time", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + ci_traceCmd.Flags().StringP("branch", "b", "", "Check pipeline status for a branch. (Default is the current branch)") + ciCmd.AddCommand(ci_traceCmd) + + carapace.Gen(ci_statusCmd).FlagCompletion(carapace.ActionMap{ + "branch": action.ActionBranches(ci_statusCmd), + }) +} diff --git a/completers/glab_completer/cmd/ci_view.go b/completers/glab_completer/cmd/ci_view.go new file mode 100644 index 0000000000..4d0950ddca --- /dev/null +++ b/completers/glab_completer/cmd/ci_view.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var ci_viewCmd = &cobra.Command{ + Use: "view", + Short: "View, run, trace/logs, and cancel CI jobs current pipeline", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + ci_viewCmd.Flags().StringP("branch", "b", "", "Check pipeline status for a branch/tag. (Default is the current branch)") + ciCmd.AddCommand(ci_viewCmd) + + carapace.Gen(ci_viewCmd).FlagCompletion(carapace.ActionMap{ + "branch": action.ActionBranches(ci_viewCmd), + }) +} diff --git a/completers/glab_completer/cmd/completion.go b/completers/glab_completer/cmd/completion.go new file mode 100644 index 0000000000..b414ae0408 --- /dev/null +++ b/completers/glab_completer/cmd/completion.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var completionCmd = &cobra.Command{ + Use: "completion", + Short: "Generate shell completion scripts", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + completionCmd.Flags().StringP("shell", "s", "bash", "Shell type: {bash|zsh|fish|powershell}") + rootCmd.AddCommand(completionCmd) + + carapace.Gen(completionCmd).FlagCompletion(carapace.ActionMap{ + "shell": carapace.ActionValues("bash", "fish", "powershell", "zsh"), + }) +} diff --git a/completers/glab_completer/cmd/config.go b/completers/glab_completer/cmd/config.go new file mode 100644 index 0000000000..d55beddd24 --- /dev/null +++ b/completers/glab_completer/cmd/config.go @@ -0,0 +1,16 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var configCmd = &cobra.Command{ + Use: "config", + Short: "Set and get glab settings", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + configCmd.Flags().BoolP("global", "g", false, "use global config file") + rootCmd.AddCommand(configCmd) +} diff --git a/completers/glab_completer/cmd/config_get.go b/completers/glab_completer/cmd/config_get.go new file mode 100644 index 0000000000..16c496101b --- /dev/null +++ b/completers/glab_completer/cmd/config_get.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var config_getCmd = &cobra.Command{ + Use: "get", + Short: "Prints the value of a given configuration key", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + config_getCmd.Flags().BoolP("global", "g", false, "Read from global config file (~/.config/glab-cli/config.yml). [Default: looks through Environment variables → Local → Global]") + config_getCmd.Flags().StringP("host", "h", "", "Get per-host setting") + configCmd.AddCommand(config_getCmd) + + carapace.Gen(config_getCmd).FlagCompletion(carapace.ActionMap{ + "host": action.ActionConfigHosts(), + }) + + carapace.Gen(config_getCmd).PositionalCompletion( + action.ActionConfigKeys(), + ) +} diff --git a/completers/glab_completer/cmd/config_init.go b/completers/glab_completer/cmd/config_init.go new file mode 100644 index 0000000000..e7de93a654 --- /dev/null +++ b/completers/glab_completer/cmd/config_init.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var config_initCmd = &cobra.Command{ + Use: "init", + Short: "Shows a prompt to set basic glab configuration", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + configCmd.AddCommand(config_initCmd) +} diff --git a/completers/glab_completer/cmd/config_set.go b/completers/glab_completer/cmd/config_set.go new file mode 100644 index 0000000000..410cd16a7a --- /dev/null +++ b/completers/glab_completer/cmd/config_set.go @@ -0,0 +1,30 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var config_setCmd = &cobra.Command{ + Use: "set", + Short: "Updates configuration with the value of a given key", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + config_setCmd.Flags().BoolP("global", "g", false, "write to global ~/.config/glab-cli/config.yml file rather than the repository .glab-cli/config/config") + config_setCmd.Flags().StringP("host", "h", "", "Set per-host setting") + configCmd.AddCommand(config_setCmd) + + carapace.Gen(config_setCmd).FlagCompletion(carapace.ActionMap{ + "host": action.ActionConfigHosts(), + }) + + carapace.Gen(config_setCmd).PositionalCompletion( + action.ActionConfigKeys(), + carapace.ActionCallback(func(c carapace.Context) carapace.Action { + return action.ActionConfigValues(c.Args[0]) + }), + ) +} diff --git a/completers/glab_completer/cmd/help.go b/completers/glab_completer/cmd/help.go new file mode 100644 index 0000000000..73873385f5 --- /dev/null +++ b/completers/glab_completer/cmd/help.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var helpCmd = &cobra.Command{ + Use: "help", + Short: "Help about any command", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + rootCmd.AddCommand(helpCmd) +} diff --git a/completers/glab_completer/cmd/issue.go b/completers/glab_completer/cmd/issue.go new file mode 100644 index 0000000000..a8c3864210 --- /dev/null +++ b/completers/glab_completer/cmd/issue.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issueCmd = &cobra.Command{ + Use: "issue", + Short: "Work with GitLab issues", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issueCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format or full URL or git URL") + rootCmd.AddCommand(issueCmd) + + carapace.Gen(issueCmd).FlagCompletion(carapace.ActionMap{ + "repo": action.ActionRepo(issueCmd), + }) +} diff --git a/completers/glab_completer/cmd/issue_board.go b/completers/glab_completer/cmd/issue_board.go new file mode 100644 index 0000000000..4d7d423013 --- /dev/null +++ b/completers/glab_completer/cmd/issue_board.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var issue_boardCmd = &cobra.Command{ + Use: "board", + Short: "Work with GitLab Issue Boards in the given project.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issueCmd.AddCommand(issue_boardCmd) +} diff --git a/completers/glab_completer/cmd/issue_board_create.go b/completers/glab_completer/cmd/issue_board_create.go new file mode 100644 index 0000000000..ee1632f773 --- /dev/null +++ b/completers/glab_completer/cmd/issue_board_create.go @@ -0,0 +1,16 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var issue_board_createCmd = &cobra.Command{ + Use: "create", + Short: "Create a project issue board.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issue_board_createCmd.Flags().StringP("name", "n", "", "The name of the new board") + issue_boardCmd.AddCommand(issue_board_createCmd) +} diff --git a/completers/glab_completer/cmd/issue_board_view.go b/completers/glab_completer/cmd/issue_board_view.go new file mode 100644 index 0000000000..0daa9da517 --- /dev/null +++ b/completers/glab_completer/cmd/issue_board_view.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var issue_board_viewCmd = &cobra.Command{ + Use: "view", + Short: "View project issue board.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issue_boardCmd.AddCommand(issue_board_viewCmd) +} diff --git a/completers/glab_completer/cmd/issue_close.go b/completers/glab_completer/cmd/issue_close.go new file mode 100644 index 0000000000..730af630f4 --- /dev/null +++ b/completers/glab_completer/cmd/issue_close.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issue_closeCmd = &cobra.Command{ + Use: "close", + Short: "Close an issue", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issueCmd.AddCommand(issue_closeCmd) + + carapace.Gen(issue_closeCmd).PositionalCompletion( + action.ActionIssues(issue_closeCmd, "opened"), + ) +} diff --git a/completers/glab_completer/cmd/issue_create.go b/completers/glab_completer/cmd/issue_create.go new file mode 100644 index 0000000000..1c8ae720c2 --- /dev/null +++ b/completers/glab_completer/cmd/issue_create.go @@ -0,0 +1,46 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issue_createCmd = &cobra.Command{ + Use: "create", + Short: "Create an issue", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issue_createCmd.Flags().StringSliceP("assignee", "a", []string{}, "Assign issue to people by their `usernames`") + issue_createCmd.Flags().BoolP("confidential", "c", false, "Set an issue to be confidential. Default is false") + issue_createCmd.Flags().StringP("description", "d", "", "Supply a description for issue") + issue_createCmd.Flags().StringSliceP("label", "l", []string{}, "Add label by name. Multiple labels should be comma separated") + issue_createCmd.Flags().String("link-type", "relates_to", "Type for the issue link") + issue_createCmd.Flags().IntSlice("linked-issues", []int{}, "The IIDs of issues that this issue links to") + issue_createCmd.Flags().Int("linked-mr", 0, "The IID of a merge request in which to resolve all issues") + issue_createCmd.Flags().StringP("milestone", "m", "", "The global ID or title of a milestone to assign") + issue_createCmd.Flags().Bool("no-editor", false, "Don't open editor to enter description. If set to true, uses prompt. Default is false") + issue_createCmd.Flags().StringP("title", "t", "", "Supply a title for issue") + issue_createCmd.Flags().Bool("web", false, "continue issue creation with web interface") + issue_createCmd.Flags().IntP("weight", "w", 0, "The weight of the issue. Valid values are greater than or equal to 0.") + issue_createCmd.Flags().BoolP("yes", "y", false, "Don't prompt for confirmation to submit the issue") + issueCmd.AddCommand(issue_createCmd) + + carapace.Gen(issue_createCmd).FlagCompletion(carapace.ActionMap{ + // TODO more flags + "assignee": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionProjectMembers(issue_createCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(issue_createCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "linked-issues": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionIssues(issue_createCmd, "opened").Invoke(c).Filter(c.Parts).ToA() + }), + "linked-mr": action.ActionMergeRequests(issue_createCmd, "opened"), + "link-type": carapace.ActionValues("relates_to", "blocks", "is_blocked_by"), + "milestone": action.ActionMilestones(issue_createCmd), + }) +} diff --git a/completers/glab_completer/cmd/issue_delete.go b/completers/glab_completer/cmd/issue_delete.go new file mode 100644 index 0000000000..2138595369 --- /dev/null +++ b/completers/glab_completer/cmd/issue_delete.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issue_deleteCmd = &cobra.Command{ + Use: "delete", + Short: "Delete an issue", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issueCmd.AddCommand(issue_deleteCmd) + + carapace.Gen(issue_deleteCmd).PositionalCompletion( + action.ActionIssues(issue_deleteCmd, "all"), + ) +} diff --git a/completers/glab_completer/cmd/issue_list.go b/completers/glab_completer/cmd/issue_list.go new file mode 100644 index 0000000000..32c0b4cf9b --- /dev/null +++ b/completers/glab_completer/cmd/issue_list.go @@ -0,0 +1,54 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issue_listCmd = &cobra.Command{ + Use: "list", + Short: "List project issues", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issue_listCmd.Flags().BoolP("all", "A", false, "Get all issues") + issue_listCmd.Flags().StringP("assignee", "a", "", "Filter issue by assignee ") + issue_listCmd.Flags().String("author", "", "Filter issue by author ") + issue_listCmd.Flags().BoolP("closed", "c", false, "Get only closed issues") + issue_listCmd.Flags().BoolP("confidential", "C", false, "Filter by confidential issues") + issue_listCmd.Flags().String("in", "title,description", "search in {title|description}") + issue_listCmd.Flags().StringSliceP("label", "l", []string{}, "Filter issue by label ") + issue_listCmd.Flags().StringP("milestone", "m", "", "Filter issue by milestone ") + issue_listCmd.Flags().BoolP("mine", "M", false, "Filter only issues issues assigned to me") + issue_listCmd.Flags().StringSlice("not-assignee", []string{}, "Filter issue by not being assigneed to ") + issue_listCmd.Flags().StringSlice("not-author", []string{}, "Filter by not being by author(s) ") + issue_listCmd.Flags().StringSlice("not-label", []string{}, "Filter issue by lack of label ") + issue_listCmd.Flags().BoolP("opened", "o", false, "Get only opened issues") + issue_listCmd.Flags().IntP("page", "p", 1, "Page number") + issue_listCmd.Flags().IntP("per-page", "P", 30, "Number of items to list per page. (default 30)") + issue_listCmd.Flags().String("search", "", "Search in the fields defined by --in") + issueCmd.AddCommand(issue_listCmd) + + carapace.Gen(issue_listCmd).FlagCompletion(carapace.ActionMap{ + "assignee": action.ActionProjectMembers(issue_listCmd), + "not-assignee": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionProjectMembers(issue_listCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "author": action.ActionProjectMembers(issue_listCmd), + "not-author": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionProjectMembers(issue_listCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "in": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return carapace.ActionValues("title", "description").Invoke(c).Filter(c.Parts).ToA() + }), + "label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(issue_listCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "not-label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(issue_listCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "milestone": action.ActionMilestones(issue_listCmd), + }) +} diff --git a/completers/glab_completer/cmd/issue_note.go b/completers/glab_completer/cmd/issue_note.go new file mode 100644 index 0000000000..5010e4d500 --- /dev/null +++ b/completers/glab_completer/cmd/issue_note.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issue_noteCmd = &cobra.Command{ + Use: "note", + Short: "Add a comment or note to an issue on GitLab", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issue_noteCmd.Flags().StringP("message", "m", "", "Comment/Note message") + issueCmd.AddCommand(issue_noteCmd) + + carapace.Gen(issue_noteCmd).PositionalCompletion( + action.ActionIssues(issue_noteCmd, "opened"), + ) +} diff --git a/completers/glab_completer/cmd/issue_reopen.go b/completers/glab_completer/cmd/issue_reopen.go new file mode 100644 index 0000000000..1ad70f8340 --- /dev/null +++ b/completers/glab_completer/cmd/issue_reopen.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issue_reopenCmd = &cobra.Command{ + Use: "reopen", + Short: "Reopen a closed issue", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issueCmd.AddCommand(issue_reopenCmd) + + carapace.Gen(issue_reopenCmd).PositionalCompletion( + action.ActionIssues(issue_reopenCmd, "closed"), + ) +} diff --git a/completers/glab_completer/cmd/issue_subscribe.go b/completers/glab_completer/cmd/issue_subscribe.go new file mode 100644 index 0000000000..a32b053fb1 --- /dev/null +++ b/completers/glab_completer/cmd/issue_subscribe.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issue_subscribeCmd = &cobra.Command{ + Use: "subscribe", + Short: "Subscribe to an issue", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issueCmd.AddCommand(issue_subscribeCmd) + + carapace.Gen(issue_subscribeCmd).PositionalCompletion( + action.ActionIssues(issue_subscribeCmd, "opened"), + ) +} diff --git a/completers/glab_completer/cmd/issue_unsubscribe.go b/completers/glab_completer/cmd/issue_unsubscribe.go new file mode 100644 index 0000000000..812d7e2bbc --- /dev/null +++ b/completers/glab_completer/cmd/issue_unsubscribe.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issue_unsubscribeCmd = &cobra.Command{ + Use: "unsubscribe", + Short: "Unsubscribe to an issue", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issueCmd.AddCommand(issue_unsubscribeCmd) + + carapace.Gen(issue_unsubscribeCmd).PositionalCompletion( + action.ActionIssues(issue_unsubscribeCmd, "opened"), + ) +} diff --git a/completers/glab_completer/cmd/issue_update.go b/completers/glab_completer/cmd/issue_update.go new file mode 100644 index 0000000000..2b25e8af66 --- /dev/null +++ b/completers/glab_completer/cmd/issue_update.go @@ -0,0 +1,45 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issue_updateCmd = &cobra.Command{ + Use: "update", + Short: "Update issue", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issue_updateCmd.Flags().StringSliceP("assignee", "a", []string{}, "assign users via username, prefix with '!' or '-' to remove from existing assignees, '+' to add, otherwise replace existing assignees with given users") + issue_updateCmd.Flags().BoolP("confidential", "c", false, "Make issue confidential") + issue_updateCmd.Flags().StringP("description", "d", "", "Issue description") + issue_updateCmd.Flags().StringSliceP("label", "l", []string{}, "add labels") + issue_updateCmd.Flags().Bool("lock-discussion", false, "Lock discussion on issue") + issue_updateCmd.Flags().StringP("milestone", "m", "", "title of the milestone to assign, pass \"\" or 0 to unassign") + issue_updateCmd.Flags().BoolP("public", "p", false, "Make issue public") + issue_updateCmd.Flags().StringP("title", "t", "", "Title of issue") + issue_updateCmd.Flags().Bool("unassign", false, "unassign all users") + issue_updateCmd.Flags().StringSliceP("unlabel", "u", []string{}, "remove labels") + issue_updateCmd.Flags().Bool("unlock-discussion", false, "Unlock discussion on issue") + issueCmd.AddCommand(issue_updateCmd) + + carapace.Gen(issue_updateCmd).FlagCompletion(carapace.ActionMap{ + "assignee": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionProjectMembers(issue_updateCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(issue_updateCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "milestone": action.ActionMilestones(issue_updateCmd), + "unlabel": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(issue_updateCmd).Invoke(c).Filter(c.Parts).ToA() + }), + }) + + carapace.Gen(issue_updateCmd).PositionalCompletion( + action.ActionIssues(issue_updateCmd, "opened"), + ) +} diff --git a/completers/glab_completer/cmd/issue_view.go b/completers/glab_completer/cmd/issue_view.go new file mode 100644 index 0000000000..7da62241b6 --- /dev/null +++ b/completers/glab_completer/cmd/issue_view.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var issue_viewCmd = &cobra.Command{ + Use: "view", + Short: "Display the title, body, and other information about an issue.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + issue_viewCmd.Flags().BoolP("comments", "c", false, "Show mr comments and activities") + issue_viewCmd.Flags().IntP("page", "p", 1, "Page number") + issue_viewCmd.Flags().IntP("per-page", "P", 20, "Number of items to list per page") + issue_viewCmd.Flags().BoolP("system-logs", "s", false, "Show system activities / logs") + issue_viewCmd.Flags().BoolP("web", "w", false, "Open mr in a browser. Uses default browser or browser specified in BROWSER variable") + issueCmd.AddCommand(issue_viewCmd) + + carapace.Gen(issue_viewCmd).PositionalCompletion( + action.ActionIssues(issue_closeCmd, "opened"), + ) +} diff --git a/completers/glab_completer/cmd/label.go b/completers/glab_completer/cmd/label.go new file mode 100644 index 0000000000..4660efe1dd --- /dev/null +++ b/completers/glab_completer/cmd/label.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var labelCmd = &cobra.Command{ + Use: "label", + Short: "Manage labels on remote", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + labelCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format or full URL or git URL") + rootCmd.AddCommand(labelCmd) + + carapace.Gen(labelCmd).FlagCompletion(carapace.ActionMap{ + "repo": action.ActionRepo(labelCmd), + }) +} diff --git a/completers/glab_completer/cmd/label_create.go b/completers/glab_completer/cmd/label_create.go new file mode 100644 index 0000000000..6d189b1ae8 --- /dev/null +++ b/completers/glab_completer/cmd/label_create.go @@ -0,0 +1,24 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var label_createCmd = &cobra.Command{ + Use: "create", + Short: "Create labels for repository/project", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + label_createCmd.Flags().StringP("color", "c", "#428BCA", "Color of label in plain or HEX code. (Default: #428BCA)") + label_createCmd.Flags().StringP("description", "d", "", "Label description") + label_createCmd.Flags().StringP("name", "n", "", "Name of label") + labelCmd.AddCommand(label_createCmd) + + carapace.Gen(label_createCmd).FlagCompletion(carapace.ActionMap{ + "name": action.ActionLabels(label_createCmd), + }) +} diff --git a/completers/glab_completer/cmd/label_list.go b/completers/glab_completer/cmd/label_list.go new file mode 100644 index 0000000000..5d7ba6b6d3 --- /dev/null +++ b/completers/glab_completer/cmd/label_list.go @@ -0,0 +1,17 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var label_listCmd = &cobra.Command{ + Use: "list", + Short: "List labels in repository", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + label_listCmd.Flags().IntP("page", "p", 1, "Page number") + label_listCmd.Flags().IntP("per-page", "P", 30, "Number of items to list per page") + labelCmd.AddCommand(label_listCmd) +} diff --git a/completers/glab_completer/cmd/mr.go b/completers/glab_completer/cmd/mr.go new file mode 100644 index 0000000000..5f6f1d504b --- /dev/null +++ b/completers/glab_completer/cmd/mr.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mrCmd = &cobra.Command{ + Use: "mr", + Short: "Create, view and manage merge requests", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format or full URL or git URL") + rootCmd.AddCommand(mrCmd) + + carapace.Gen(mrCmd).FlagCompletion(carapace.ActionMap{ + "repo": action.ActionRepo(mrCmd), + }) +} diff --git a/completers/glab_completer/cmd/mr_approve.go b/completers/glab_completer/cmd/mr_approve.go new file mode 100644 index 0000000000..d2357617e0 --- /dev/null +++ b/completers/glab_completer/cmd/mr_approve.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_approveCmd = &cobra.Command{ + Use: "approve", + Short: "Approve merge requests", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mr_approveCmd.Flags().StringP("sha", "s", "", "SHA which must match the SHA of the HEAD commit of the merge request") + mrCmd.AddCommand(mr_approveCmd) + + carapace.Gen(mr_approveCmd).PositionalAnyCompletion( + action.ActionMergeRequestsAndBranches(mr_approveCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_approvers.go b/completers/glab_completer/cmd/mr_approvers.go new file mode 100644 index 0000000000..dc16f8c2f5 --- /dev/null +++ b/completers/glab_completer/cmd/mr_approvers.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_approversCmd = &cobra.Command{ + Use: "approvers", + Short: "List merge request eligible approvers", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.AddCommand(mr_approversCmd) + + carapace.Gen(mr_approversCmd).PositionalCompletion( + action.ActionMergeRequestsAndBranches(mr_approversCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_checkout.go b/completers/glab_completer/cmd/mr_checkout.go new file mode 100644 index 0000000000..474700e3b4 --- /dev/null +++ b/completers/glab_completer/cmd/mr_checkout.go @@ -0,0 +1,29 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_checkoutCmd = &cobra.Command{ + Use: "checkout", + Short: "Checkout to an open merge request", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mr_checkoutCmd.Flags().StringP("branch", "b", "", "checkout merge request with name") + mr_checkoutCmd.Flags().StringP("set-upstream-to", "u", "", "set tracking of checked out branch to [REMOTE/]BRANCH") + mr_checkoutCmd.Flags().BoolP("track", "t", false, "set checked out branch to track remote branch, adds remote if needed") + mrCmd.AddCommand(mr_checkoutCmd) + + carapace.Gen(mr_checkoutCmd).FlagCompletion(carapace.ActionMap{ + "branch": action.ActionBranches(mr_checkoutCmd), + // TODO "set-upstream-to": + }) + + carapace.Gen(mr_checkoutCmd).PositionalAnyCompletion( + action.ActionMergeRequestsAndBranches(mr_checkoutCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_close.go b/completers/glab_completer/cmd/mr_close.go new file mode 100644 index 0000000000..0119f96448 --- /dev/null +++ b/completers/glab_completer/cmd/mr_close.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_closeCmd = &cobra.Command{ + Use: "close", + Short: "Close merge requests", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.AddCommand(mr_closeCmd) + + carapace.Gen(mr_closeCmd).PositionalAnyCompletion( + action.ActionMergeRequestsAndBranches(mr_closeCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_create.go b/completers/glab_completer/cmd/mr_create.go new file mode 100644 index 0000000000..478ce7bfd2 --- /dev/null +++ b/completers/glab_completer/cmd/mr_create.go @@ -0,0 +1,48 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_createCmd = &cobra.Command{ + Use: "create", + Short: "Create new merge request", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mr_createCmd.Flags().Bool("allow-collaboration", false, "Allow commits from other members") + mr_createCmd.Flags().StringSliceP("assignee", "a", []string{}, "Assign merge request to people by their `usernames`") + mr_createCmd.Flags().Bool("create-source-branch", false, "Create source branch if it does not exist") + mr_createCmd.Flags().StringP("description", "d", "", "Supply a description for merge request") + mr_createCmd.Flags().Bool("draft", false, "Mark merge request as a draft") + mr_createCmd.Flags().BoolP("fill", "f", false, "Do not prompt for title/description and just use commit info") + mr_createCmd.Flags().StringP("head", "H", "", "Select another head repository using the `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format or the project ID or full URL") + mr_createCmd.Flags().StringSliceP("label", "l", []string{}, "Add label by name. Multiple labels should be comma separated") + mr_createCmd.Flags().StringP("milestone", "m", "", "The global ID or title of a milestone to assign") + mr_createCmd.Flags().Bool("no-editor", false, "Don't open editor to enter description. If set to true, uses prompt. Default is false") + mr_createCmd.Flags().Bool("push", false, "Push committed changes after creating merge request. Make sure you have committed changes") + mr_createCmd.Flags().Bool("remove-source-branch", false, "Remove Source Branch on merge") + mr_createCmd.Flags().StringP("source-branch", "s", "", "The Branch you are creating the merge request. Default is the current branch.") + mr_createCmd.Flags().StringP("target-branch", "b", "", "The target or base branch into which you want your code merged") + mr_createCmd.Flags().String("target-project", "", "Add target project by id or OWNER/REPO or GROUP/NAMESPACE/REPO") + mr_createCmd.Flags().StringP("title", "t", "", "Supply a title for merge request") + mr_createCmd.Flags().BoolP("web", "w", false, "continue merge request creation on web browser") + mr_createCmd.Flags().Bool("wip", false, "Mark merge request as a work in progress. Alternative to --draft") + mr_createCmd.Flags().BoolP("yes", "y", false, "Skip submission confirmation prompt, with --fill it skips all optional prompts") + mrCmd.AddCommand(mr_createCmd) + + carapace.Gen(mr_createCmd).FlagCompletion(carapace.ActionMap{ + "assignee": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionProjectMembers(mr_createCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(mr_createCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "milestone": action.ActionMilestones(mr_createCmd), + "source-branch": action.ActionBranches(mr_createCmd), + "target-branch": action.ActionBranches(mr_createCmd), + }) +} diff --git a/completers/glab_completer/cmd/mr_delete.go b/completers/glab_completer/cmd/mr_delete.go new file mode 100644 index 0000000000..4808e25247 --- /dev/null +++ b/completers/glab_completer/cmd/mr_delete.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_deleteCmd = &cobra.Command{ + Use: "delete", + Short: "Delete merge requests", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.AddCommand(mr_deleteCmd) + + carapace.Gen(mr_deleteCmd).PositionalAnyCompletion( + action.ActionMergeRequestsAndBranches(mr_deleteCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_diff.go b/completers/glab_completer/cmd/mr_diff.go new file mode 100644 index 0000000000..edcf9f03a2 --- /dev/null +++ b/completers/glab_completer/cmd/mr_diff.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_diffCmd = &cobra.Command{ + Use: "diff", + Short: "View changes in a merge request", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mr_diffCmd.Flags().String("color", "auto", "Use color in diff output: {always|never|auto}") + mrCmd.AddCommand(mr_diffCmd) + + carapace.Gen(mr_diffCmd).FlagCompletion(carapace.ActionMap{ + "color": carapace.ActionValues("always", "never", "auto"), + }) + + carapace.Gen(mr_diffCmd).PositionalAnyCompletion( + action.ActionMergeRequestsAndBranches(mr_diffCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_for.go b/completers/glab_completer/cmd/mr_for.go new file mode 100644 index 0000000000..52beb7d3d7 --- /dev/null +++ b/completers/glab_completer/cmd/mr_for.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_forCmd = &cobra.Command{ + Use: "for", + Short: "Create new merge request for an issue", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mr_forCmd.Flags().Bool("allow-collaboration", false, "Allow commits from other members") + mr_forCmd.Flags().StringP("assignee", "a", "", "Assign merge request to people by their IDs. Multiple values should be comma separated ") + mr_forCmd.Flags().Bool("draft", true, "Mark merge request as a draft. Default is true") + mr_forCmd.Flags().StringP("label", "l", "", "Add label by name. Multiple labels should be comma separated") + mr_forCmd.Flags().IntP("milestone", "m", -1, "add milestone by for merge request") + mr_forCmd.Flags().Bool("remove-source-branch", false, "Remove Source Branch on merge") + mr_forCmd.Flags().StringP("target-branch", "b", "", "The target or base branch into which you want your code merged") + mr_forCmd.Flags().Bool("wip", false, "Mark merge request as a work in progress. Overrides --draft") + mr_forCmd.Flags().Bool("with-labels", false, "Copy labels from issue to the merge request") + mrCmd.AddCommand(mr_forCmd) + + carapace.Gen(mr_forCmd).FlagCompletion(carapace.ActionMap{ + "assignee": action.ActionProjectMembers(mr_forCmd), + "label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(mr_forCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "target-branch": action.ActionBranches(mr_forCmd), + }) + + carapace.Gen(mr_forCmd).PositionalCompletion( + action.ActionIssues(mr_forCmd, "opened"), + ) +} diff --git a/completers/glab_completer/cmd/mr_issues.go b/completers/glab_completer/cmd/mr_issues.go new file mode 100644 index 0000000000..bb621809e1 --- /dev/null +++ b/completers/glab_completer/cmd/mr_issues.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_issuesCmd = &cobra.Command{ + Use: "issues", + Short: "Get issues related to a particular merge request.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.AddCommand(mr_issuesCmd) + + carapace.Gen(mr_issuesCmd).PositionalAnyCompletion( + action.ActionMergeRequestsAndBranches(mr_issuesCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_list.go b/completers/glab_completer/cmd/mr_list.go new file mode 100644 index 0000000000..9d6d823058 --- /dev/null +++ b/completers/glab_completer/cmd/mr_list.go @@ -0,0 +1,53 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_listCmd = &cobra.Command{ + Use: "list", + Short: "List merge requests", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mr_listCmd.Flags().BoolP("all", "A", false, "Get all merge requests") + mr_listCmd.Flags().StringSliceP("assignee", "a", []string{}, "Get only merge requests assigned to users") + mr_listCmd.Flags().String("author", "", "Fitler merge request by Author ") + mr_listCmd.Flags().BoolP("closed", "c", false, "Get only closed merge requests") + mr_listCmd.Flags().BoolP("draft", "d", false, "Filter by draft merge requests") + mr_listCmd.Flags().StringSliceP("label", "l", []string{}, "Filter merge request by label ") + mr_listCmd.Flags().BoolP("merged", "M", false, "Get only merged merge requests") + mr_listCmd.Flags().StringP("milestone", "m", "", "Filter merge request by milestone ") + mr_listCmd.Flags().Bool("mine", false, "Get only merge requests assigned to me") + mr_listCmd.Flags().StringSlice("not-label", []string{}, "Filter merge requests by not having label ") + mr_listCmd.Flags().BoolP("opened", "o", false, "Get only open merge requests") + mr_listCmd.Flags().IntP("page", "p", 1, "Page number") + mr_listCmd.Flags().IntP("per-page", "P", 30, "Number of items to list per page") + mr_listCmd.Flags().StringSliceP("reviewer", "r", []string{}, "Get only merge requests with users as reviewer") + mr_listCmd.Flags().String("search", "", "Filter by in title and description") + mr_listCmd.Flags().StringP("source-branch", "s", "", "Filter by source branch ") + mr_listCmd.Flags().StringP("target-branch", "t", "", "Filter by target branch ") + mrCmd.AddCommand(mr_listCmd) + + carapace.Gen(mr_listCmd).FlagCompletion(carapace.ActionMap{ + "assignee": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionProjectMembers(mr_listCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "author": action.ActionProjectMembers(mr_listCmd), + "label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(mr_listCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "not-label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(mr_listCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "milestone": action.ActionMilestones(mr_listCmd), + "reviewer": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionProjectMembers(mr_listCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "source-branch": action.ActionBranches(mr_listCmd), + "target-branch": action.ActionBranches(mr_listCmd), + }) +} diff --git a/completers/glab_completer/cmd/mr_merge.go b/completers/glab_completer/cmd/mr_merge.go new file mode 100644 index 0000000000..f1cfebf22b --- /dev/null +++ b/completers/glab_completer/cmd/mr_merge.go @@ -0,0 +1,29 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_mergeCmd = &cobra.Command{ + Use: "merge", + Short: "Merge/Accept merge requests", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mr_mergeCmd.Flags().StringP("message", "m", "", "Custom merge commit message") + mr_mergeCmd.Flags().BoolP("rebase", "r", false, "Rebase the commits onto the base branch") + mr_mergeCmd.Flags().BoolP("remove-source-branch", "d", false, "Remove source branch on merge") + mr_mergeCmd.Flags().String("sha", "", "Merge Commit sha") + mr_mergeCmd.Flags().BoolP("squash", "s", false, "Squash commits on merge") + mr_mergeCmd.Flags().String("squash-message", "", "Custom Squash commit message") + mr_mergeCmd.Flags().Bool("when-pipeline-succeeds", true, "Merge only when pipeline succeeds") + mr_mergeCmd.Flags().BoolP("yes", "y", false, "Skip submission confirmation prompt") + mrCmd.AddCommand(mr_mergeCmd) + + carapace.Gen(mr_mergeCmd).PositionalAnyCompletion( + action.ActionMergeRequestsAndBranches(mr_mergeCmd, "opened"), + ) +} diff --git a/completers/glab_completer/cmd/mr_note.go b/completers/glab_completer/cmd/mr_note.go new file mode 100644 index 0000000000..04c0c5bca7 --- /dev/null +++ b/completers/glab_completer/cmd/mr_note.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_noteCmd = &cobra.Command{ + Use: "note", + Short: "Add a comment or note to merge request", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mr_noteCmd.Flags().StringP("message", "m", "", "Comment/Note message") + mrCmd.AddCommand(mr_noteCmd) + + carapace.Gen(mr_noteCmd).PositionalAnyCompletion( + action.ActionMergeRequestsAndBranches(mr_noteCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_rebase.go b/completers/glab_completer/cmd/mr_rebase.go new file mode 100644 index 0000000000..b7218a9378 --- /dev/null +++ b/completers/glab_completer/cmd/mr_rebase.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_rebaseCmd = &cobra.Command{ + Use: "rebase", + Short: "Automatically rebase the source_branch of the merge request against its target_branch.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.AddCommand(mr_rebaseCmd) + + carapace.Gen(mr_rebaseCmd).PositionalCompletion( + action.ActionMergeRequestsAndBranches(mr_rebaseCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_reopen.go b/completers/glab_completer/cmd/mr_reopen.go new file mode 100644 index 0000000000..a90139bd25 --- /dev/null +++ b/completers/glab_completer/cmd/mr_reopen.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_reopenCmd = &cobra.Command{ + Use: "reopen", + Short: "Reopen merge requests", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.AddCommand(mr_reopenCmd) + + carapace.Gen(mr_reopenCmd).PositionalCompletion( + action.ActionMergeRequestsAndBranches(mr_reopenCmd, "closed"), + ) +} diff --git a/completers/glab_completer/cmd/mr_revoke.go b/completers/glab_completer/cmd/mr_revoke.go new file mode 100644 index 0000000000..21baa73ed4 --- /dev/null +++ b/completers/glab_completer/cmd/mr_revoke.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_revokeCmd = &cobra.Command{ + Use: "revoke", + Short: "Revoke approval on a merge request ", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.AddCommand(mr_revokeCmd) + + carapace.Gen(mr_revokeCmd).PositionalCompletion( + action.ActionMergeRequestsAndBranches(mr_revokeCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_subscribe.go b/completers/glab_completer/cmd/mr_subscribe.go new file mode 100644 index 0000000000..094494f51c --- /dev/null +++ b/completers/glab_completer/cmd/mr_subscribe.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_subscribeCmd = &cobra.Command{ + Use: "subscribe", + Short: "Subscribe to merge requests", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.AddCommand(mr_subscribeCmd) + + carapace.Gen(mr_subscribeCmd).PositionalCompletion( + action.ActionMergeRequestsAndBranches(mr_subscribeCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_todo.go b/completers/glab_completer/cmd/mr_todo.go new file mode 100644 index 0000000000..f8a1315dee --- /dev/null +++ b/completers/glab_completer/cmd/mr_todo.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_todoCmd = &cobra.Command{ + Use: "todo", + Short: "Add a ToDo to merge request", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.AddCommand(mr_todoCmd) + + carapace.Gen(mr_todoCmd).PositionalCompletion( + action.ActionMergeRequestsAndBranches(mr_todoCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_unsubscribe.go b/completers/glab_completer/cmd/mr_unsubscribe.go new file mode 100644 index 0000000000..3b233ea147 --- /dev/null +++ b/completers/glab_completer/cmd/mr_unsubscribe.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_unsubscribeCmd = &cobra.Command{ + Use: "unsubscribe", + Short: "Unsubscribe from merge requests", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mrCmd.AddCommand(mr_unsubscribeCmd) + + carapace.Gen(mr_unsubscribeCmd).PositionalCompletion( + action.ActionMergeRequestsAndBranches(mr_unsubscribeCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_update.go b/completers/glab_completer/cmd/mr_update.go new file mode 100644 index 0000000000..b73e1f91db --- /dev/null +++ b/completers/glab_completer/cmd/mr_update.go @@ -0,0 +1,53 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_updateCmd = &cobra.Command{ + Use: "update", + Short: "Update merge requests", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mr_updateCmd.Flags().StringSliceP("assignee", "a", []string{}, "assign users via username, prefix with '!' or '-' to remove from existing assignees, '+' to add, otherwise replace existing assignees with given users") + mr_updateCmd.Flags().StringP("description", "d", "", "merge request description") + mr_updateCmd.Flags().Bool("draft", false, "Mark merge request as a draft") + mr_updateCmd.Flags().StringSliceP("label", "l", []string{}, "add labels") + mr_updateCmd.Flags().Bool("lock-discussion", false, "Lock discussion on merge request") + mr_updateCmd.Flags().StringP("milestone", "m", "", "title of the milestone to assign, pass \"\" or 0 to unassign") + mr_updateCmd.Flags().BoolP("ready", "r", false, "Mark merge request as ready to be reviewed and merged") + mr_updateCmd.Flags().Bool("remove-source-branch", false, "Remove Source Branch on merge") + mr_updateCmd.Flags().StringSlice("reviewer", []string{}, "request review from users by their usernames, prefix with '!' or '-' to remove from existing reviewers, '+' to add, otherwise replace existing reviewers with given users") + mr_updateCmd.Flags().String("target-branch", "", "set target branch") + mr_updateCmd.Flags().StringP("title", "t", "", "Title of merge request") + mr_updateCmd.Flags().Bool("unassign", false, "unassign all users") + mr_updateCmd.Flags().StringSliceP("unlabel", "u", []string{}, "remove labels") + mr_updateCmd.Flags().Bool("unlock-discussion", false, "Unlock discussion on merge request") + mr_updateCmd.Flags().Bool("wip", false, "Mark merge request as a work in progress. Alternative to --draft") + mrCmd.AddCommand(mr_updateCmd) + + carapace.Gen(mr_updateCmd).FlagCompletion(carapace.ActionMap{ + "assignee": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionProjectMembers(mr_updateCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "label": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(mr_updateCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "milestone": action.ActionMilestones(mr_updateCmd), + "reviewer": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionProjectMembers(mr_updateCmd).Invoke(c).Filter(c.Parts).ToA() + }), + "target-branch": action.ActionBranches(mr_updateCmd), + "unlabel": carapace.ActionMultiParts(",", func(c carapace.Context) carapace.Action { + return action.ActionLabels(mr_updateCmd).Invoke(c).Filter(c.Parts).ToA() + }), + }) + + carapace.Gen(mr_updateCmd).PositionalCompletion( + action.ActionMergeRequestsAndBranches(mr_updateCmd, ""), + ) +} diff --git a/completers/glab_completer/cmd/mr_view.go b/completers/glab_completer/cmd/mr_view.go new file mode 100644 index 0000000000..d5ea497bbd --- /dev/null +++ b/completers/glab_completer/cmd/mr_view.go @@ -0,0 +1,26 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var mr_viewCmd = &cobra.Command{ + Use: "view", + Short: "Display the title, body, and other information about a merge request.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + mr_viewCmd.Flags().BoolP("comments", "c", false, "Show mr comments and activities") + mr_viewCmd.Flags().IntP("page", "p", 0, "Page number") + mr_viewCmd.Flags().IntP("per-page", "P", 20, "Number of items to list per page") + mr_viewCmd.Flags().BoolP("system-logs", "s", false, "Show system activities / logs") + mr_viewCmd.Flags().BoolP("web", "w", false, "Open mr in a browser. Uses default browser or browser specified in BROWSER variable") + mrCmd.AddCommand(mr_viewCmd) + + carapace.Gen(mr_viewCmd).PositionalCompletion( + action.ActionMergeRequestsAndBranches(mr_viewCmd, "opened"), + ) +} diff --git a/completers/glab_completer/cmd/release.go b/completers/glab_completer/cmd/release.go new file mode 100644 index 0000000000..a66e0a58db --- /dev/null +++ b/completers/glab_completer/cmd/release.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var releaseCmd = &cobra.Command{ + Use: "release", + Short: "Manage GitLab releases", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + releaseCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format or full URL or git URL") + rootCmd.AddCommand(releaseCmd) + + carapace.Gen(releaseCmd).FlagCompletion(carapace.ActionMap{ + "repo": action.ActionRepo(releaseCmd), + }) +} diff --git a/completers/glab_completer/cmd/release_list.go b/completers/glab_completer/cmd/release_list.go new file mode 100644 index 0000000000..3b66324630 --- /dev/null +++ b/completers/glab_completer/cmd/release_list.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var release_listCmd = &cobra.Command{ + Use: "list", + Short: "List releases in a repository", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + release_listCmd.Flags().StringP("tag", "t", "", "Filter releases by tag ") + releaseCmd.AddCommand(release_listCmd) + + carapace.Gen(release_listCmd).FlagCompletion(carapace.ActionMap{ + "tag": action.ActionTags(release_listCmd), + }) +} diff --git a/completers/glab_completer/cmd/repo.go b/completers/glab_completer/cmd/repo.go new file mode 100644 index 0000000000..eebdf42858 --- /dev/null +++ b/completers/glab_completer/cmd/repo.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var repoCmd = &cobra.Command{ + Use: "repo", + Short: "Work with GitLab repositories and projects", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + rootCmd.AddCommand(repoCmd) +} diff --git a/completers/glab_completer/cmd/repo_archive.go b/completers/glab_completer/cmd/repo_archive.go new file mode 100644 index 0000000000..ba80819941 --- /dev/null +++ b/completers/glab_completer/cmd/repo_archive.go @@ -0,0 +1,33 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var repo_archiveCmd = &cobra.Command{ + Use: "archive", + Short: "Get an archive of the repository.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + repo_archiveCmd.Flags().StringP("format", "f", "zip", "Optionally Specify format if you want a downloaded archive: {tar.gz|tar.bz2|tbz|tbz2|tb2|bz2|tar|zip} (Default: zip)") + repo_archiveCmd.Flags().StringP("sha", "s", "", "The commit SHA to download. A tag, branch reference, or SHA can be used. This defaults to the tip of the default branch if not specified") + repoCmd.AddCommand(repo_archiveCmd) + + carapace.Gen(repo_archiveCmd).FlagCompletion(carapace.ActionMap{ + "format": carapace.ActionValues("tar.gz", "tar.bz2", "tbz", "tbz2", "tb2", "bz2", "tar", "zip"), + "sha": carapace.ActionCallback(func(c carapace.Context) carapace.Action { + branches := action.ActionBranches(repo_archiveCmd).Invoke(c) + tags := action.ActionTags(repo_archiveCmd).Invoke(c) + return branches.Merge(tags).ToA() // TODO sha + }), + }) + + carapace.Gen(repo_archiveCmd).PositionalCompletion( + action.ActionRepo(repo_archiveCmd), + carapace.ActionDirectories(), + ) +} diff --git a/completers/glab_completer/cmd/repo_clone.go b/completers/glab_completer/cmd/repo_clone.go new file mode 100644 index 0000000000..6d745a83ab --- /dev/null +++ b/completers/glab_completer/cmd/repo_clone.go @@ -0,0 +1,36 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var repo_cloneCmd = &cobra.Command{ + Use: "clone", + Short: "Clone a Gitlab repository/project", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + repo_cloneCmd.Flags().BoolP("archived", "a", false, "Limit by archived status. Used with --group flag") + repo_cloneCmd.Flags().StringP("group", "g", "", "Specify group to clone repositories from") + repo_cloneCmd.Flags().BoolP("include-subgroups", "G", true, "Include projects in subgroups of this group. Default is true. Used with --group flag") + repo_cloneCmd.Flags().BoolP("mine", "m", false, "Limit by projects in the group owned by the current authenticated user. Used with --group flag") + repo_cloneCmd.Flags().BoolP("preserve-namespace", "p", false, "Clone the repo in a subdirectory based on namespace") + repo_cloneCmd.Flags().StringP("visibility", "v", "", "Limit by visibility {public, internal, or private}. Used with --group flag") + repo_cloneCmd.Flags().BoolP("with-issues-enabled", "I", false, "Limit by projects with issues feature enabled. Default is false. Used with --group flag") + repo_cloneCmd.Flags().BoolP("with-mr-enabled", "M", false, "Limit by projects with issues feature enabled. Default is false. Used with --group flag") + repo_cloneCmd.Flags().BoolP("with-shared", "S", false, "Include projects shared to this group. Default is false. Used with --group flag") + repoCmd.AddCommand(repo_cloneCmd) + + carapace.Gen(repo_cloneCmd).FlagCompletion(carapace.ActionMap{ + "group": action.ActionGroups(repo_cloneCmd), + "visibility": carapace.ActionValues("public", "internal", "private"), + }) + + carapace.Gen(repo_cloneCmd).PositionalCompletion( + action.ActionRepo(repo_cloneCmd), // TODO not yet correct - also needs to consider flags being set + carapace.ActionDirectories(), + ) +} diff --git a/completers/glab_completer/cmd/repo_contributors.go b/completers/glab_completer/cmd/repo_contributors.go new file mode 100644 index 0000000000..c85ab30018 --- /dev/null +++ b/completers/glab_completer/cmd/repo_contributors.go @@ -0,0 +1,28 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var repo_contributorsCmd = &cobra.Command{ + Use: "contributors", + Short: "Get repository contributors list.", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + repo_contributorsCmd.Flags().StringP("order", "o", "commits", "Return contributors ordered by name, email, or commits (orders by commit date) fields") + repo_contributorsCmd.Flags().IntP("page", "p", 1, "Page number") + repo_contributorsCmd.Flags().IntP("per-page", "P", 30, "Number of items to list per page.") + repo_contributorsCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format or full URL or git URL") + repo_contributorsCmd.Flags().StringP("sort", "s", "", "Return contributors sorted in asc or desc order") + repoCmd.AddCommand(repo_contributorsCmd) + + carapace.Gen(repo_contributorsCmd).FlagCompletion(carapace.ActionMap{ + "order": carapace.ActionValues("name", "email", "commits"), + "repo": action.ActionRepo(repo_contributorsCmd), + "sort": carapace.ActionValues("asc", "desc"), + }) +} diff --git a/completers/glab_completer/cmd/repo_create.go b/completers/glab_completer/cmd/repo_create.go new file mode 100644 index 0000000000..3cd1cf7275 --- /dev/null +++ b/completers/glab_completer/cmd/repo_create.go @@ -0,0 +1,34 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var repo_createCmd = &cobra.Command{ + Use: "create", + Short: "Create a new Gitlab project/repository", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + repo_createCmd.Flags().String("defaultBranch", "", "Default branch of the project. If not provided, `master` by default.") + repo_createCmd.Flags().StringP("description", "d", "", "Description of the new project") + repo_createCmd.Flags().StringP("group", "g", "", "Namespace/group for the new project (defaults to the current user’s namespace)") + repo_createCmd.Flags().Bool("internal", false, "Make project internal: visible to any authenticated user (default)") + repo_createCmd.Flags().StringP("name", "n", "", "Name of the new project") + repo_createCmd.Flags().BoolP("private", "p", false, "Make project private: visible only to project members") + repo_createCmd.Flags().BoolP("public", "P", false, "Make project public: visible without any authentication") + repo_createCmd.Flags().Bool("readme", false, "Initialize project with README.md") + repo_createCmd.Flags().StringArrayP("tag", "t", []string{}, "The list of tags for the project.") + repoCmd.AddCommand(repo_createCmd) + + carapace.Gen(repo_createCmd).FlagCompletion(carapace.ActionMap{ + "group": action.ActionGroups(repo_createCmd), + }) + + carapace.Gen(repo_createCmd).PositionalCompletion( + action.ActionRepo(repo_createCmd), + ) +} diff --git a/completers/glab_completer/cmd/repo_delete.go b/completers/glab_completer/cmd/repo_delete.go new file mode 100644 index 0000000000..079edbdc3b --- /dev/null +++ b/completers/glab_completer/cmd/repo_delete.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var repo_deleteCmd = &cobra.Command{ + Use: "delete", + Short: "Delete an existing repository on GitLab", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + repo_deleteCmd.Flags().BoolP("yes", "y", false, "Skip the confirmation prompt and immediately delete the repository.") + repoCmd.AddCommand(repo_deleteCmd) + + carapace.Gen(repo_deleteCmd).PositionalCompletion( + action.ActionRepo(repo_deleteCmd), + ) +} diff --git a/completers/glab_completer/cmd/repo_fork.go b/completers/glab_completer/cmd/repo_fork.go new file mode 100644 index 0000000000..345d57115f --- /dev/null +++ b/completers/glab_completer/cmd/repo_fork.go @@ -0,0 +1,27 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var repo_forkCmd = &cobra.Command{ + Use: "fork", + Short: "Create a fork of a GitLab repository", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + repo_forkCmd.Flags().BoolP("clone", "c", false, "Clone the fork {true|false}") + repo_forkCmd.Flags().StringP("name", "n", "", "The name assigned to the resultant project after forking") + repo_forkCmd.Flags().StringP("path", "p", "", "The path assigned to the resultant project after forking") + repo_forkCmd.Flags().Bool("remote", false, "Add remote for fork {true|false}") + repoCmd.AddCommand(repo_forkCmd) + + // TODO path completion + + carapace.Gen(repo_forkCmd).PositionalCompletion( + action.ActionRepo(repo_forkCmd), + ) +} diff --git a/completers/glab_completer/cmd/repo_search.go b/completers/glab_completer/cmd/repo_search.go new file mode 100644 index 0000000000..3c75c29d48 --- /dev/null +++ b/completers/glab_completer/cmd/repo_search.go @@ -0,0 +1,18 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var repo_searchCmd = &cobra.Command{ + Use: "search", + Short: "Search for GitLab repositories and projects by name", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + repo_searchCmd.Flags().IntP("page", "p", 1, "Page number") + repo_searchCmd.Flags().IntP("per-page", "P", 20, "Number of items to list per page") + repo_searchCmd.Flags().StringP("search", "s", "", "A string contained in the project name") + repoCmd.AddCommand(repo_searchCmd) +} diff --git a/completers/glab_completer/cmd/root.go b/completers/glab_completer/cmd/root.go new file mode 100644 index 0000000000..86c3664e7b --- /dev/null +++ b/completers/glab_completer/cmd/root.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" +) + +var rootCmd = &cobra.Command{ + Use: "glab", + Short: "A GitLab CLI Tool", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func Execute() error { + return rootCmd.Execute() +} + +func init() { + rootCmd.PersistentFlags().Bool("help", false, "Show help for command") + rootCmd.Flags().BoolP("version", "v", false, "show glab version information") + + carapace.Gen(rootCmd) +} diff --git a/completers/glab_completer/cmd/user.go b/completers/glab_completer/cmd/user.go new file mode 100644 index 0000000000..c5b3b194df --- /dev/null +++ b/completers/glab_completer/cmd/user.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var userCmd = &cobra.Command{ + Use: "user", + Short: "Interact with user", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + rootCmd.AddCommand(userCmd) +} diff --git a/completers/glab_completer/cmd/user_events.go b/completers/glab_completer/cmd/user_events.go new file mode 100644 index 0000000000..f895ad4d50 --- /dev/null +++ b/completers/glab_completer/cmd/user_events.go @@ -0,0 +1,16 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var user_eventsCmd = &cobra.Command{ + Use: "events", + Short: "View user events", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + user_eventsCmd.Flags().BoolP("all", "a", false, "Get events from all projects") + userCmd.AddCommand(user_eventsCmd) +} diff --git a/completers/glab_completer/cmd/variable.go b/completers/glab_completer/cmd/variable.go new file mode 100644 index 0000000000..8c9161f0c0 --- /dev/null +++ b/completers/glab_completer/cmd/variable.go @@ -0,0 +1,22 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var variableCmd = &cobra.Command{ + Use: "variable", + Short: "Manage GitLab Project and Group Variables", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + variableCmd.PersistentFlags().StringP("repo", "R", "", "Select another repository using the `OWNER/REPO` or `GROUP/NAMESPACE/REPO` format or full URL or git URL") + rootCmd.AddCommand(variableCmd) + + carapace.Gen(variableCmd).FlagCompletion(carapace.ActionMap{ + "repo": action.ActionRepo(variableCmd), + }) +} diff --git a/completers/glab_completer/cmd/variable_set.go b/completers/glab_completer/cmd/variable_set.go new file mode 100644 index 0000000000..a4714f1bbc --- /dev/null +++ b/completers/glab_completer/cmd/variable_set.go @@ -0,0 +1,37 @@ +package cmd + +import ( + "github.com/rsteube/carapace" + "github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action" + "github.com/spf13/cobra" +) + +var variable_setCmd = &cobra.Command{ + Use: "set", + Short: "Create a new project or group variable", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + variable_setCmd.Flags().StringP("group", "g", "", "Set variable for a group") + variable_setCmd.Flags().BoolP("masked", "m", false, "Whether the variable is masked") + variable_setCmd.Flags().BoolP("protected", "p", false, "Whether the variable is protected") + variable_setCmd.Flags().StringP("scope", "s", "*", "The environment_scope of the variable. All (*), or specific environments") + variable_setCmd.Flags().StringP("type", "t", "env_var", "The type of a variable: {env_var|file}") + variable_setCmd.Flags().StringP("value", "v", "", "The value of a variable") + variableCmd.AddCommand(variable_setCmd) + + carapace.Gen(variable_setCmd).FlagCompletion(carapace.ActionMap{ + "type": carapace.ActionValues("env_var", "file"), + "group": action.ActionGroups(variableCmd), + "scope": carapace.ActionCallback(func(c carapace.Context) carapace.Action { + all := carapace.ActionValues("*").Invoke(c) + environments := action.ActionEnvironments(variable_setCmd).Invoke(c) + return all.Merge(environments).ToA() + }), + }) + + carapace.Gen(variable_setCmd).PositionalCompletion( + action.ActionVariables(variableCmd), + ) +} diff --git a/completers/glab_completer/cmd/version.go b/completers/glab_completer/cmd/version.go new file mode 100644 index 0000000000..0b2dce1a9f --- /dev/null +++ b/completers/glab_completer/cmd/version.go @@ -0,0 +1,15 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var versionCmd = &cobra.Command{ + Use: "version", + Short: "show glab version information", + Run: func(cmd *cobra.Command, args []string) {}, +} + +func init() { + rootCmd.AddCommand(versionCmd) +} diff --git a/completers/glab_completer/main.go b/completers/glab_completer/main.go new file mode 100644 index 0000000000..9f4ac5c0ab --- /dev/null +++ b/completers/glab_completer/main.go @@ -0,0 +1,7 @@ +package main + +import "github.com/rsteube/carapace-bin/completers/glab_completer/cmd" + +func main() { + cmd.Execute() +}