Skip to content

Commit

Permalink
Cleanup a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
XiaoConstantine committed Jul 16, 2024
1 parent 7daa328 commit ba54b85
Showing 1 changed file with 22 additions and 5 deletions.
27 changes: 22 additions & 5 deletions pkg/commands/extensions/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ func NewCmdExtension(iostream *iostreams.IOStreams) *cobra.Command {
cmd := &cobra.Command{
Use: "extension",
Short: "Manage mycli extensions",
Annotations: map[string]string{
"group": "extension",
},
}

cmd.AddCommand(newExtensionInstallCmd(iostream))
Expand All @@ -66,15 +69,17 @@ func newExtensionInstallCmd(iostream *iostreams.IOStreams) *cobra.Command {
return &cobra.Command{
Use: "install <repository>",
Short: "Install a mycli extension",
Args: cobra.ExactArgs(1),
Annotations: map[string]string{
"group": "extension",
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
repo := args[0]
extDir := getExtensionDir()
extName := filepath.Base(repo)
extName = strings.TrimSuffix(extName, ".git")
// Remove the ExtensionPrefix if it's already there
extName = strings.TrimPrefix(extName, ExtensionPrefix)
fmt.Fprintf(iostream.Out, "Extension name: %s\n", extName)
extPath := filepath.Join(extDir, ExtensionPrefix+extName)
fmt.Fprintf(iostream.Out, "Extension path: %s\n", extPath)

Expand All @@ -100,6 +105,9 @@ func newExtensionListCmd(iostream *iostreams.IOStreams) *cobra.Command {
return &cobra.Command{
Use: "list",
Short: "List installed mycli extensions",
Annotations: map[string]string{
"group": "extension",
},
RunE: func(cmd *cobra.Command, args []string) error {
extDir := GetExtensionsDir()
entries, err := os.ReadDir(extDir)
Expand All @@ -125,7 +133,10 @@ func newExtensionRemoveCmd(iostream *iostreams.IOStreams) *cobra.Command {
return &cobra.Command{
Use: "remove <extension-name>",
Short: "Remove a mycli extension",
Args: cobra.ExactArgs(1),
Annotations: map[string]string{
"group": "extension",
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
extName := args[0]
extDir := GetExtensionsDir()
Expand All @@ -145,7 +156,10 @@ func newExtensionUpdateCmd(iostream *iostreams.IOStreams) *cobra.Command {
return &cobra.Command{
Use: "update <extension-name>",
Short: "Update a mycli extension",
Args: cobra.ExactArgs(1),
Annotations: map[string]string{
"group": "extension",
},
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
extName := args[0]
extDir := GetExtensionsDir()
Expand All @@ -169,7 +183,10 @@ func newExtensionRunCmd() *cobra.Command {
return &cobra.Command{
Use: "run <extension-name> [args...]",
Short: "Run a mycli extension",
Args: cobra.MinimumNArgs(1),
Annotations: map[string]string{
"group": "extension",
},
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
return fmt.Errorf("extension name is required")
Expand Down

0 comments on commit ba54b85

Please sign in to comment.