Skip to content

Commit

Permalink
add loading
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan committed May 25, 2022
1 parent 6a7cbd0 commit ff81284
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 8 deletions.
6 changes: 1 addition & 5 deletions command.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
10 changes: 10 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
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=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
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=
26 changes: 23 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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())
}
}

0 comments on commit ff81284

Please sign in to comment.