From b4f649014ecfcc07bf185b458732f874180133b6 Mon Sep 17 00:00:00 2001 From: samuelmjn <34322984+samuelmjn@users.noreply.github.com> Date: Tue, 14 Apr 2020 13:08:57 +0700 Subject: [PATCH] feature: add command to update fer to latest version (#14) Co-authored-by: Samuel Mulatua --- console/common.go | 10 ++++++++-- console/root.go | 4 +++- console/update.go | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 console/update.go diff --git a/console/common.go b/console/common.go index 670dc2a..de1393e 100644 --- a/console/common.go +++ b/console/common.go @@ -1,11 +1,12 @@ package console import ( - "github.com/gookit/color" - "github.com/kumparan/fer/config" "log" "os/user" "path/filepath" + + "github.com/gookit/color" + "github.com/kumparan/fer/config" ) // PrintError :nodoc: @@ -23,6 +24,11 @@ func PrintWarn(format string, args ...interface{}) { color.Warn.Printf(format, args...) } +// PrintSuccess :nodoc: +func PrintSuccess(format string, args ...interface{}) { + color.Success.Printf(format, args...) +} + // GetConfigDir :nodoc: func GetConfigDir() string { return filepath.Join(GetHomeDir(), config.ConfigDir) diff --git a/console/root.go b/console/root.go index 4d8eea0..6d197f6 100644 --- a/console/root.go +++ b/console/root.go @@ -1,8 +1,9 @@ package console import ( - "github.com/spf13/cobra" "os" + + "github.com/spf13/cobra" ) // RootCmd represents the base command when called without any subcommands @@ -35,4 +36,5 @@ func init() { rootCmd.AddCommand(installCmd) rootCmd.AddCommand(initCmd) rootCmd.AddCommand(createCmd) + rootCmd.AddCommand(updateCmd) } diff --git a/console/update.go b/console/update.go new file mode 100644 index 0000000..e61d410 --- /dev/null +++ b/console/update.go @@ -0,0 +1,33 @@ +package console + +import ( + "fmt" + "os" + "os/exec" + + "github.com/kumparan/fer/installer" + "github.com/spf13/cobra" +) + +var updateCmd = &cobra.Command{ + Use: "update", + Short: "update fer", + Long: `update fer to latest version`, + Run: updateVersion, +} + +func updateVersion(cmd *cobra.Command, args []string) { + updateCommand := exec.Command("go", "get", "-u", "github.com/kumparan/fer") + PrintInfo("Updating fer...") + err := updateCommand.Run() + if err != nil { + installer.ProgressBar(1) + fmt.Println("Failed updating fer") + fmt.Println(err) + os.Exit(1) + } + + installer.ProgressBar(100) + + PrintSuccess("Success updating fer!") +}