Skip to content

Commit

Permalink
Merge pull request #529 from rsteube/glab-new-commands
Browse files Browse the repository at this point in the history
glab: new commands from 1.19.0
  • Loading branch information
rsteube authored Aug 10, 2021
2 parents fd1480e + d14906e commit 3a84608
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 0 deletions.
9 changes: 9 additions & 0 deletions completers/glab_completer/cmd/action/repoOverride.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@ import (
"strings"
)

func FakeRepoFlag(cmd *cobra.Command, value string) {
cmd.Flags().StringP("repo", "R", value, "fake repo flag")
cmd.Flag("repo").Changed = true
}

func ActionRepo(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if flag := cmd.Flag("repo"); flag == nil {
FakeRepoFlag(cmd, c.CallbackValue)
}

configHosts, err := hosts()
if err != nil {
return carapace.ActionMessage(err.Error())
Expand Down
26 changes: 26 additions & 0 deletions completers/glab_completer/cmd/action/sshKey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package action

import (
"strconv"

"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

type sshKey struct {
Id int
Title string
}

func ActionSshKeyIds(cmd *cobra.Command) carapace.Action {
return carapace.ActionCallback(func(c carapace.Context) carapace.Action {
var queryResult []sshKey
return actionApi(cmd, "/user/keys", &queryResult, func() carapace.Action {
vals := make([]string, 0, len(queryResult)*2)
for _, sshKey := range queryResult {
vals = append(vals, strconv.Itoa(sshKey.Id), sshKey.Title)
}
return carapace.ActionValuesDescribed(vals...)
})
})
}
35 changes: 35 additions & 0 deletions completers/glab_completer/cmd/repo_view.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/glab_completer/cmd/action"
"github.com/spf13/cobra"
)

var repo_viewCmd = &cobra.Command{
Use: "view [repository] [flags]",
Short: "View a project/repository",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(repo_viewCmd).Standalone()
repo_viewCmd.Flags().StringP("branch", "b", "", "View a specific branch of the repository")
repo_viewCmd.Flags().BoolP("web", "w", false, "Open a project in the browser")

repoCmd.AddCommand(repo_viewCmd)

carapace.Gen(repo_viewCmd).FlagCompletion(carapace.ActionMap{
"branch": carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if len(c.Args) > 0 {
action.FakeRepoFlag(repo_viewCmd, c.Args[0])
return action.ActionBranches(repo_viewCmd)
}
return carapace.ActionValues()
}),
})

carapace.Gen(repo_viewCmd).PositionalCompletion(
action.ActionRepo(repo_viewCmd),
)
}
18 changes: 18 additions & 0 deletions completers/glab_completer/cmd/sshKey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var sshKeyCmd = &cobra.Command{
Use: "ssh-key <command>",
Short: "Manage SSH keys",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(sshKeyCmd).Standalone()

rootCmd.AddCommand(sshKeyCmd)
}
24 changes: 24 additions & 0 deletions completers/glab_completer/cmd/sshKey_add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var sshKey_addCmd = &cobra.Command{
Use: "add",
Short: "Add an SSH key to your GitLab account",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(sshKey_addCmd).Standalone()
sshKey_addCmd.Flags().StringP("expires-at", "e", "", "The expiration date of the SSH key in ISO 8601 format (YYYY-MM-DDTHH:MM:SSZ)")
sshKey_addCmd.Flags().StringP("title", "t", "", "New SSH key's title")

sshKeyCmd.AddCommand(sshKey_addCmd)

carapace.Gen(sshKey_addCmd).PositionalCompletion(
carapace.ActionFiles(),
)
}
23 changes: 23 additions & 0 deletions completers/glab_completer/cmd/sshKey_get.go
Original file line number Diff line number Diff line change
@@ -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 sshKey_getCmd = &cobra.Command{
Use: "get <key-id>",
Short: "Gets a single key",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(sshKey_getCmd).Standalone()

sshKeyCmd.AddCommand(sshKey_getCmd)

carapace.Gen(sshKey_getCmd).PositionalCompletion(
action.ActionSshKeyIds(sshKeyCmd),
)
}
19 changes: 19 additions & 0 deletions completers/glab_completer/cmd/sshKey_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
)

var sshKey_listCmd = &cobra.Command{
Use: "list",
Short: "Lists currently authenticated user’s SSH keys",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(sshKey_listCmd).Standalone()
sshKey_listCmd.Flags().BoolP("show-id", "", false, "Show IDs of SSH Keys")

sshKeyCmd.AddCommand(sshKey_listCmd)
}
24 changes: 24 additions & 0 deletions completers/glab_completer/cmd/variable_list.go
Original file line number Diff line number Diff line change
@@ -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 variable_listCmd = &cobra.Command{
Use: "list",
Short: "List project or group variables",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(variable_listCmd).Standalone()
variable_listCmd.Flags().StringP("group", "g", "", "List group variables")

variableCmd.AddCommand(variable_listCmd)

carapace.Gen(variable_listCmd).FlagCompletion(carapace.ActionMap{
"group": action.ActionGroups(variable_listCmd),
})
}

0 comments on commit 3a84608

Please sign in to comment.