Skip to content

Commit

Permalink
feature: add command to update fer to latest version (#14)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Mulatua <[email protected]>
  • Loading branch information
samuelmjn and Samuel Mulatua authored Apr 14, 2020
1 parent 845fa8e commit b4f6490
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
10 changes: 8 additions & 2 deletions console/common.go
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion console/root.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -35,4 +36,5 @@ func init() {
rootCmd.AddCommand(installCmd)
rootCmd.AddCommand(initCmd)
rootCmd.AddCommand(createCmd)
rootCmd.AddCommand(updateCmd)
}
33 changes: 33 additions & 0 deletions console/update.go
Original file line number Diff line number Diff line change
@@ -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!")
}

0 comments on commit b4f6490

Please sign in to comment.