Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit b76d7e4

Browse files
committed
feat: parameterize commands (#20)
1 parent 436ded9 commit b76d7e4

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

cmd/plugin/plugin.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ func NewCommand(out output.Output) *cobra.Command {
2929

3030
// InstallCommand creates a new command to install
3131
func InstallCommand(out output.Output) *cobra.Command {
32-
return &cobra.Command{
32+
var (
33+
pluginName string
34+
pluginVersion string
35+
pluginURL string
36+
)
37+
38+
cmd := &cobra.Command{
3339
Use: "install",
3440
Short: "Installs a tool for a specific plugin",
3541
RunE: func(cmd *cobra.Command, args []string) error {
@@ -42,19 +48,29 @@ func InstallCommand(out output.Output) *cobra.Command {
4248

4349
err = defaultSource.InstallPluginVersion(
4450
&types.InstallPluginVersionRequest{
45-
Name: "golang",
46-
Version: "1.19.3",
51+
Name: pluginName,
52+
Version: pluginVersion,
53+
URL: pluginURL,
4754
},
4855
)
56+
4957
if err != nil {
5058
return fmt.Errorf("failed to install plugin: %w", err)
5159
}
5260

53-
fmt.Printf("installed plugin %s with version %s\n", "golang", "1.19.3")
61+
fmt.Printf("installed plugin %s with version %s\n", pluginName, pluginVersion)
5462

5563
return nil
5664
},
5765
}
66+
67+
cmd.Flags().StringVar(&pluginName, "name", "", "name of the plugin")
68+
cmd.Flags().StringVar(&pluginVersion, "version", "", "version of the plugin")
69+
cmd.Flags().StringVar(&pluginURL, "url", "", "url of the plugin")
70+
cmd.MarkFlagRequired("name")
71+
cmd.MarkFlagRequired("version")
72+
73+
return cmd
5874
}
5975

6076
// ListCommand creates a new command to remove a plugin

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2021 D2iQ, Inc. All rights reserved.
1+
// Copyright 2022 D2iQ, Inc. All rights reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

44
package main

0 commit comments

Comments
 (0)