Skip to content

Commit

Permalink
feat: parameterize commands (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
mstruebing committed Dec 14, 2022
1 parent 436ded9 commit b76d7e4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
24 changes: 20 additions & 4 deletions cmd/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,13 @@ func NewCommand(out output.Output) *cobra.Command {

// InstallCommand creates a new command to install
func InstallCommand(out output.Output) *cobra.Command {
return &cobra.Command{
var (
pluginName string
pluginVersion string
pluginURL string
)

cmd := &cobra.Command{
Use: "install",
Short: "Installs a tool for a specific plugin",
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -42,19 +48,29 @@ func InstallCommand(out output.Output) *cobra.Command {

err = defaultSource.InstallPluginVersion(
&types.InstallPluginVersionRequest{
Name: "golang",
Version: "1.19.3",
Name: pluginName,
Version: pluginVersion,
URL: pluginURL,
},
)

if err != nil {
return fmt.Errorf("failed to install plugin: %w", err)
}

fmt.Printf("installed plugin %s with version %s\n", "golang", "1.19.3")
fmt.Printf("installed plugin %s with version %s\n", pluginName, pluginVersion)

return nil
},
}

cmd.Flags().StringVar(&pluginName, "name", "", "name of the plugin")
cmd.Flags().StringVar(&pluginVersion, "version", "", "version of the plugin")
cmd.Flags().StringVar(&pluginURL, "url", "", "url of the plugin")
cmd.MarkFlagRequired("name")
cmd.MarkFlagRequired("version")

return cmd
}

// ListCommand creates a new command to remove a plugin
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021 D2iQ, Inc. All rights reserved.
// Copyright 2022 D2iQ, Inc. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

package main
Expand Down

0 comments on commit b76d7e4

Please sign in to comment.