Skip to content

Commit

Permalink
Add upgrade command
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Nov 23, 2021
1 parent db77336 commit 7c9b380
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
7 changes: 5 additions & 2 deletions help.txt
@@ -1,11 +1,14 @@
aho v%s

Usage:
aho [options] <repo> [destination="."]
Commands:
<repo> [destination] Download a repository and generate to destination directory
upgrade Upgrade aho itself to the latest version

Options:
-f, --force
-p, --path <path> Use a sub directory instead of the whole directory
-h, --help Show this help
-v, --version Show version

Examples:
aho egoist/ts-lib-starter out-folder
Expand Down
5 changes: 4 additions & 1 deletion internal/args.go
Expand Up @@ -47,7 +47,10 @@ func ParseArgs(args []string, help string, version string) (*AppArgs, error) {
return nil, fmt.Errorf("unknown flag: %s", arg)
}
} else {
if repo == "" {
if arg == "upgrade" {
Upgrade()
os.Exit(0)
} else if repo == "" {
repo = arg
} else if destination == "" {
destination = arg
Expand Down
21 changes: 21 additions & 0 deletions internal/upgrade.go
@@ -0,0 +1,21 @@
package internal

import (
"os"
"os/exec"
"path"
)

func Upgrade() {
bin := os.Args[0]
dir := path.Dir(bin)

// Run command
cmd := exec.Command("bash", "-c", "curl -fsSL https://install.egoist.sh/aho.sh | bash -s -- -b "+dir)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr

cmd.Run()

}

0 comments on commit 7c9b380

Please sign in to comment.