Skip to content

integrated multiple plugin install feature #131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions cmd/selm/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,30 @@ import (
"github.com/spf13/cobra"
)

var pluginName string
var pluginNames string

// pluginInstallCmd is a subcommand that installs a Helm plugin.
// pluginInstallCmd is a subcommand that installs multiple Helm plugins.
var pluginInstallCmd = &cobra.Command{
Use: "plugin install [PLUGIN]",
Short: "Install a Helm plugin.",
Use: "plugin install [PLUGINS]",
Short: "Install one or more Helm plugins (comma-separated).",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
pluginName = args[0]
if pluginName == "" {
return errors.New(color.RedString("PLUGIN name must be provided"))
pluginNames = args[0]
if pluginNames == "" {
return errors.New(color.RedString("At least one PLUGIN name must be provided"))
}

pterm.Info.Println(fmt.Sprintf("Installing Helm plugin: %s", pluginName))
err := helm.HelmPluginInstall(pluginName)
pterm.Info.Println(fmt.Sprintf("Installing Helm plugins: %s", pluginNames))
err := helm.HelmPluginInstall(pluginNames)
if err != nil {
return errors.New(color.RedString("Helm plugin install failed: %v", err))
}
pterm.Success.Println("Helm plugin installed successfully.")
pterm.Success.Println("Helm plugins installed successfully.")
return nil
},
Example: `
smurf selm plugin https://github.com/helm/helm-secrets
smurf selm plugin https://github.com/helm/helm-secrets,https://github.com/helm/helm-diff
`,
}

Expand Down
26 changes: 18 additions & 8 deletions internal/helm/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ package helm
import (
"fmt"
"os/exec"
"strings"
)

// HelmPluginInstall installs a Helm plugin
func HelmPluginInstall(pluginURL string) error {
cmd := exec.Command("helm", "plugin", "install", pluginURL)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to install Helm plugin: %v, output: %s", err, output)
// HelmPluginInstall installs one or more Helm plugins
func HelmPluginInstall(plugins string) error {
pluginList := strings.Split(plugins, ",")
for _, plugin := range pluginList {
plugin = strings.TrimSpace(plugin)
if plugin == "" {
continue
}
fmt.Printf("Installing Helm plugin: %s\n", plugin)
cmd := exec.Command("helm", "plugin", "install", plugin)
output, err := cmd.CombinedOutput()
if err != nil {
fmt.Printf("Failed to install Helm plugin: %s\nError: %v\nOutput: %s\n", plugin, err, output)
continue
}
fmt.Printf("Helm plugin installed successfully: %s\n", plugin)
}
fmt.Printf("Helm plugin installed successfully: %s\n", output)
return nil
}
}