diff --git a/command.go b/command.go index 4aa9b38..fdb4b52 100644 --- a/command.go +++ b/command.go @@ -1,13 +1,9 @@ package main -import ( - "os" - "os/exec" -) +import "os/exec" func getCmdOutput(cmds ...string) ([]byte, error) { command := exec.Command(cmds[0], cmds[1:]...) - command.Stderr = os.Stderr output, err := command.Output() if err != nil { return nil, err diff --git a/go.mod b/go.mod index 3f67039..f232518 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,11 @@ go 1.18 require github.com/olekukonko/tablewriter v0.0.5 require ( + github.com/briandowns/spinner v1.18.1 // indirect + github.com/fatih/color v1.7.0 // indirect + github.com/mattn/go-colorable v0.1.2 // indirect + github.com/mattn/go-isatty v0.0.8 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect github.com/rivo/uniseg v0.2.0 // indirect + golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 // indirect ) diff --git a/go.sum b/go.sum index b904dad..943fe1d 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,11 @@ +github.com/briandowns/spinner v1.18.1 h1:yhQmQtM1zsqFsouh09Bk/jCjd50pC3EOGsh28gLVvwY= +github.com/briandowns/spinner v1.18.1/go.mod h1:mQak9GHqbspjC/5iUx3qMlIho8xBS/ppAL/hX5SmPJU= +github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys= +github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4= +github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU= +github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= +github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE= +github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI= github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU= github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= @@ -5,3 +13,5 @@ github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY= github.com/rivo/uniseg v0.2.0 h1:S1pD9weZBuJdFmowNwbpi7BJ8TNftyUImj/0WQi72jY= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8= +golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= diff --git a/main.go b/main.go index c579e86..dbf477d 100644 --- a/main.go +++ b/main.go @@ -1,25 +1,35 @@ package main import ( - "fmt" "os" + "os/exec" + "time" + "github.com/briandowns/spinner" + "github.com/fatih/color" "github.com/olekukonko/tablewriter" ) func main() { + spin := spinner.New(spinner.CharSets[14], 100*time.Millisecond) + spin.Suffix = " Checking for updates..." + spin.Start() + directs, err := getDirectModules() if err != nil { - fmt.Fprintf(os.Stderr, "parseGoMod: %v\n", err) + spin.Stop() + processError("parseGoMod", err) return } modules, err := getDepPackages() if err != nil { - fmt.Fprintf(os.Stderr, "parseModules: %v\n", err) + spin.Stop() + processError("parseModules", err) return } + spin.Stop() table := tablewriter.NewWriter(os.Stdout) table.SetHeader([]string{"Package", "Current", "Latest", "GoVersion"}) table.SetBorder(false) @@ -52,3 +62,13 @@ func contains(list []string, str string) bool { return false } + +func processError(action string, err error) { + writer := color.New(color.FgRed) + if e, ok := err.(*exec.ExitError); ok { + writer.Fprintf(os.Stderr, "%s: %s", action, string(e.Stderr)) + os.Exit(e.ExitCode()) + } else { + writer.Fprintf(os.Stderr, "%s: %s\n", action, err.Error()) + } +}