mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-15 01:12:56 +03:00
be8b46d37a
PR-URL: https://github.com/hasura/graphql-engine-mono/pull/6736 GitOrigin-RevId: d155a2abce4dd8094ff071a8d05af4174a96f3b9
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
package commands
|
|
|
|
/*
|
|
some of the code here is borrowed from the krew codebse (kubernetes)
|
|
and the copyright belongs to the respective authors.
|
|
|
|
source: https://github.com/kubernetes-sigs/krew/blob/master/cmd/krew/cmd/uninstall.go
|
|
*/
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hasura/graphql-engine/cli/v2"
|
|
"github.com/hasura/graphql-engine/cli/v2/internal/errors"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newPluginsUnInstallCmd(ec *cli.ExecutionContext) *cobra.Command {
|
|
pluginsUnInstallCmd := &cobra.Command{
|
|
Use: "uninstall [plugin-name]",
|
|
Short: "Uninstall a plugin",
|
|
Example: ` # Uninstall a plugin
|
|
hasura plugins uninstall [plugin-name]`,
|
|
SilenceUsage: true,
|
|
Args: cobra.ExactArgs(1),
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
|
op := genOpName(cmd, "PreRunE")
|
|
if err := ec.Prepare(); err != nil {
|
|
return errors.E(op, err)
|
|
}
|
|
return nil
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
op := genOpName(cmd, "RunE")
|
|
pluginName := args[0]
|
|
ec.Spin(fmt.Sprintf("Uninstalling plugin %q", pluginName))
|
|
defer ec.Spinner.Stop()
|
|
if err := ec.PluginsConfig.Uninstall(pluginName); err != nil {
|
|
return errors.E(op,fmt.Errorf("failed to uninstall plugin %s: %w", pluginName, err))
|
|
}
|
|
ec.Spinner.Stop()
|
|
ec.Logger.WithField("name", pluginName).Infoln("plugin uninstalled")
|
|
return nil
|
|
},
|
|
}
|
|
return pluginsUnInstallCmd
|
|
}
|