mirror of
https://github.com/hasura/graphql-engine.git
synced 2024-12-14 17:02:49 +03:00
bb63d7e60e
Co-authored-by: Rishichandra Wawhal <rishichandra.wawhal@gmail.com> Co-authored-by: Rikin Kachhia <54616969+rikinsk@users.noreply.github.com> Co-authored-by: Aravind <aravindkp@outlook.in> Co-authored-by: Anon Ray <ecthiender@users.noreply.github.com> Co-authored-by: Shahidh K Muhammed <muhammedshahid.k@gmail.com>
50 lines
1.4 KiB
Go
50 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/upgrade.go
|
|
*/
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
|
|
"github.com/hasura/graphql-engine/cli"
|
|
"github.com/hasura/graphql-engine/cli/plugins"
|
|
"github.com/pkg/errors"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func newPluginsUpgradeCmd(ec *cli.ExecutionContext) *cobra.Command {
|
|
pluginsUpgradeCmd := &cobra.Command{
|
|
Use: "upgrade",
|
|
Short: "Upgrade a plugin to a newer version",
|
|
Example: ` # Upgrade a plugin to a newer version
|
|
hasura plugins upgrade [plugin-name]`,
|
|
SilenceUsage: true,
|
|
Args: cobra.ExactArgs(1),
|
|
PreRunE: func(cmd *cobra.Command, args []string) error {
|
|
return ec.Prepare()
|
|
},
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
pluginName := args[0]
|
|
ec.Spin(fmt.Sprintf("Upgrading plugin %q...", pluginName))
|
|
defer ec.Spinner.Stop()
|
|
plugin, err := ec.PluginsConfig.Upgrade(pluginName)
|
|
if err != nil && err != plugins.ErrIsAlreadyUpgraded {
|
|
return errors.Wrapf(err, "failed to upgrade plugin %q", plugin.Name)
|
|
}
|
|
ec.Spinner.Stop()
|
|
ec.Logger.WithFields(logrus.Fields{
|
|
"name": pluginName,
|
|
"version": plugin.Version,
|
|
}).Infoln("Plugin upgraded")
|
|
return nil
|
|
},
|
|
}
|
|
return pluginsUpgradeCmd
|
|
}
|