Skip to content

Commit

Permalink
gh: extension completion
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Sep 23, 2022
1 parent a6ab2c6 commit 2797897
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
23 changes: 23 additions & 0 deletions completers/gh-dash_completer/cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

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

var rootCmd = &cobra.Command{
Use: "gh-dash",
Short: "A beautiful CLI dashboard for GitHub",
Long: "https://github.com/dlvhdr/gh-dash",
Run: func(cmd *cobra.Command, args []string) {},
}

func Execute() error {
return rootCmd.Execute()
}
func init() {
carapace.Gen(rootCmd).Standalone()

rootCmd.Flags().BoolS("debug", "debug", false, "passing this flag will allow writing debug output to debug.log")

}
7 changes: 7 additions & 0 deletions completers/gh-dash_completer/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

import "github.com/rsteube/carapace-bin/completers/gh-dash_completer/cmd"

func main() {
cmd.Execute()
}
15 changes: 14 additions & 1 deletion completers/gh_completer/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"github.com/rsteube/carapace"
"github.com/rsteube/carapace-bin/completers/gh_completer/cmd/action"
"github.com/rsteube/carapace-bin/pkg/actions/bridge"
"github.com/spf13/cobra"
)

Expand All @@ -28,9 +29,21 @@ func init() {
cmd.Root().AddCommand(&cobra.Command{Use: key, Short: value, Run: func(cmd *cobra.Command, args []string) {}})
}
}

if extensions, err := action.Extensions(); err == nil {
for _, extension := range extensions {
cmd.Root().AddCommand(&cobra.Command{Use: extension, Short: "extension", Run: func(cmd *cobra.Command, args []string) {}})
extensionCmd := &cobra.Command{
Use: extension,
Short: "extension",
Run: func(cmd *cobra.Command, args []string) {},
DisableFlagParsing: true,
}

carapace.Gen(extensionCmd).PositionalAnyCompletion(
bridge.ActionCarapaceBin("gh-" + extension),
)

rootCmd.AddCommand(extensionCmd)
}
}
})
Expand Down

0 comments on commit 2797897

Please sign in to comment.