[mike@mwxm4]
This commit is contained in:
@@ -140,6 +140,12 @@ func printHelp() {
|
||||
fmt.Println(" base <C> Change base currency (e.g., base USD)")
|
||||
fmt.Println(" clear Clear the terminal screen")
|
||||
fmt.Println(" exit/quit Exit goca")
|
||||
fmt.Println("\033[1mUpdates:\033[0m")
|
||||
fmt.Println(" goca --version Print the version")
|
||||
fmt.Println(" goca --check-update Look for a newer release")
|
||||
fmt.Println(" goca --update Download and install the newest release")
|
||||
fmt.Println(" goca looks for a new release once a day, in the background, and says so on")
|
||||
fmt.Println(" stderr. GOCA_NO_UPDATE_CHECK=1 or -y turns that off.")
|
||||
}
|
||||
|
||||
type CalcCompleter struct{}
|
||||
@@ -533,22 +539,55 @@ func handleLine(line string, useReadline bool, variablesFile string, functionsFi
|
||||
return false
|
||||
}
|
||||
|
||||
func main() {
|
||||
initUnits()
|
||||
// printUpdateHint puts the note of the daily look on stderr, dimmed, so that it
|
||||
// never lands in a pipe that only expects the result.
|
||||
func printUpdateHint(hint string) {
|
||||
if hint != "" {
|
||||
fmt.Fprintf(os.Stderr, "\033[2m%s\033[0m\n", hint)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// The options come before everything else: --update-refresh is the
|
||||
// background run and must touch neither units nor rates, and --version has
|
||||
// to answer at once — the updater probes the downloaded binary with it.
|
||||
optY := false
|
||||
newArgs := []string{os.Args[0]}
|
||||
for i := 1; i < len(os.Args); i++ {
|
||||
if os.Args[i] == "-y" {
|
||||
switch os.Args[i] {
|
||||
case "-y":
|
||||
optY = true
|
||||
} else {
|
||||
case "--version":
|
||||
fmt.Printf("goca %s\n", Version)
|
||||
return
|
||||
case "--update":
|
||||
if err := selfUpdate.install(os.Stdout); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "goca: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
case "--check-update":
|
||||
if err := selfUpdate.check(os.Stdout); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "goca: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return
|
||||
case updateRefreshFlag: // the background run, not in the help
|
||||
selfUpdate.refresh()
|
||||
return
|
||||
default:
|
||||
newArgs = append(newArgs, os.Args[i])
|
||||
}
|
||||
}
|
||||
os.Args = newArgs
|
||||
|
||||
initUnits()
|
||||
|
||||
// Costs nothing: the hint comes from the note in the cache, and the asking
|
||||
// happens once a day at most, in the background. -y keeps it quiet.
|
||||
updateHint := ""
|
||||
if !optY {
|
||||
checkforupdate(UPDATEURL)
|
||||
updateHint = selfUpdate.daily()
|
||||
}
|
||||
|
||||
hasArgs := len(os.Args) > 1
|
||||
@@ -576,6 +615,7 @@ func main() {
|
||||
if arg == "-p" || arg == "--port" {
|
||||
if i+1 < len(os.Args) {
|
||||
port := os.Args[i+1]
|
||||
printUpdateHint(updateHint)
|
||||
startWebServer(port)
|
||||
return
|
||||
} else {
|
||||
@@ -587,6 +627,7 @@ func main() {
|
||||
|
||||
input := strings.Join(os.Args[1:], " ")
|
||||
handleLine(input, false, variablesFile, functionsFile)
|
||||
printUpdateHint(updateHint)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -614,6 +655,7 @@ func main() {
|
||||
|
||||
if useReadline {
|
||||
fmt.Printf("\033[1;34mgoca v%s\033[0m, type 'help' for examples.\n", Version)
|
||||
printUpdateHint(updateHint)
|
||||
}
|
||||
|
||||
var scanner *bufio.Scanner
|
||||
@@ -639,4 +681,8 @@ func main() {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
if !useReadline { // piped input: the hint comes at the end, not before it
|
||||
printUpdateHint(updateHint)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user