Skip to content

Commit

Permalink
Updates to update command
Browse files Browse the repository at this point in the history
  • Loading branch information
leaanthony committed May 6, 2019
1 parent bb3dbe0 commit 0daec29
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 6 deletions.
9 changes: 7 additions & 2 deletions cmd/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func (p *ProgramHelper) RunCommand(command string) error {
}

// RunCommandArray runs the command specified in the array
func (p *ProgramHelper) RunCommandArray(args []string) error {
func (p *ProgramHelper) RunCommandArray(args []string, dir ...string) error {
program := args[0]
// TODO: Run FindProgram here and get the full path to the exe
program, err := exec.LookPath(program)
Expand All @@ -116,8 +116,13 @@ func (p *ProgramHelper) RunCommandArray(args []string) error {
return err
}
args = args[1:]
var stderr string
// fmt.Printf("RunCommandArray = %s %+v\n", program, args)
_, stderr, err := p.shell.Run(program, args...)
if len(dir) > 0 {
_, stderr, err = p.shell.RunInDirectory(dir[0], program, args...)
} else {
_, stderr, err = p.shell.Run(program, args...)
}
if err != nil {
fmt.Println(stderr)
}
Expand Down
13 changes: 13 additions & 0 deletions cmd/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,16 @@ func (sh *ShellHelper) Run(command string, vars ...string) (stdout, stderr strin
stderr = string(stde.Bytes())
return
}

// RunInDirectory runs the given command in the given directory
func (sh *ShellHelper) RunInDirectory(dir string, command string, vars ...string) (stdout, stderr string, err error) {
cmd := exec.Command(command, vars...)
cmd.Dir = dir
var stdo, stde bytes.Buffer
cmd.Stdout = &stdo
cmd.Stderr = &stde
err = cmd.Run()
stdout = string(stdo.Bytes())
stderr = string(stde.Bytes())
return
}
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package cmd

// Version - Wails version
const Version = "v0.12.0"
const Version = "v0.12.3"
11 changes: 10 additions & 1 deletion cmd/wails/8_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"encoding/json"
"fmt"
"io/ioutil"
"log"
"net/http"

"github.com/leaanthony/spinner"
"github.com/mitchellh/go-homedir"
"github.com/wailsapp/wails/cmd"
)

Expand Down Expand Up @@ -54,7 +56,14 @@ func init() {
updateSpinner := spinner.NewSpinner()
updateSpinner.SetSpinSpeed(40)
updateSpinner.Start("Updating to : " + latestVersion)
err = cmd.NewProgramHelper().RunCommandArray([]string{"go", "get", "-u", "github.com/wailsapp/wails/cmd/wails"})

// Run command in non module directory
homeDir, err := homedir.Dir()
if err != nil {
log.Fatal("Cannot find home directory! Please file a bug report!")
}

err = cmd.NewProgramHelper().RunCommandArray([]string{"go", "get", "github.com/wailsapp/wails/.../."}, homeDir)
if err != nil {
updateSpinner.Error(err.Error())
return err
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGi
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.2 h1:DB17ag19krx9CFsz4o3enTrPXyIXCl+2iCXH/aMAp9s=
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/leaanthony/mewn v0.10.4 h1:b16/E0r6CuXN8WYuDJIgwRocLQlmMjfBsooEJr6FdqY=
github.com/leaanthony/mewn v0.10.4/go.mod h1:i3ygCWW96qVQlGa8sjWnTM0IKAijoFvTwATDIZgK4k0=
github.com/leaanthony/mewn v0.10.5 h1:QKYVj8tI94alvVFZer7wPy66IcNpyNPITIkdhXbThX4=
github.com/leaanthony/mewn v0.10.5/go.mod h1:i3ygCWW96qVQlGa8sjWnTM0IKAijoFvTwATDIZgK4k0=
github.com/leaanthony/slicer v1.3.1 h1:n2iIV2sxvL/3bpnmVY0vBjXf3yYFWcB6CYLVMrzJxRw=
Expand Down

0 comments on commit 0daec29

Please sign in to comment.