2020-02-24 19:14:46 +03:00
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"
2021-06-16 14:44:15 +03:00
"github.com/hasura/graphql-engine/cli/v2"
2022-11-08 12:57:24 +03:00
"github.com/hasura/graphql-engine/cli/v2/internal/errors"
2022-12-30 06:50:48 +03:00
2020-02-24 19:14:46 +03:00
"github.com/spf13/cobra"
)
func newPluginsUnInstallCmd ( ec * cli . ExecutionContext ) * cobra . Command {
pluginsUnInstallCmd := & cobra . Command {
Use : "uninstall [plugin-name]" ,
Short : "Uninstall a plugin" ,
2022-12-30 06:50:48 +03:00
Long : "To uninstall a plugin, run the uninstall command with the name of the plugin as an argument. If unsure of the plugin's name, you can run the `Hasura plugins list` command to see a list of all the available plugins." ,
2020-02-24 19:14:46 +03:00
Example : ` # Uninstall a plugin
hasura plugins uninstall [ plugin - name ] ` ,
SilenceUsage : true ,
Args : cobra . ExactArgs ( 1 ) ,
PreRunE : func ( cmd * cobra . Command , args [ ] string ) error {
2022-11-08 12:57:24 +03:00
op := genOpName ( cmd , "PreRunE" )
if err := ec . Prepare ( ) ; err != nil {
return errors . E ( op , err )
}
return nil
2020-02-24 19:14:46 +03:00
} ,
RunE : func ( cmd * cobra . Command , args [ ] string ) error {
2022-11-08 12:57:24 +03:00
op := genOpName ( cmd , "RunE" )
2020-02-24 19:14:46 +03:00
pluginName := args [ 0 ]
ec . Spin ( fmt . Sprintf ( "Uninstalling plugin %q" , pluginName ) )
defer ec . Spinner . Stop ( )
if err := ec . PluginsConfig . Uninstall ( pluginName ) ; err != nil {
2022-12-30 06:50:48 +03:00
return errors . E ( op , fmt . Errorf ( "failed to uninstall plugin %s: %w" , pluginName , err ) )
2020-02-24 19:14:46 +03:00
}
ec . Spinner . Stop ( )
ec . Logger . WithField ( "name" , pluginName ) . Infoln ( "plugin uninstalled" )
return nil
} ,
}
return pluginsUnInstallCmd
}