Skip to content

Commit

Permalink
Show version number without an error exit code.
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouture committed Aug 23, 2021
1 parent 578c1a0 commit ffab879
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions cmd/nv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,20 @@ import (
)

func main() {
if len(os.Args) == 2 {
cmd := os.Args[1]
switch cmd {
case "-v", "version", "-version", "--version":
printVersion()
default:
printHelp()
}
os.Exit(0)
}

if len(os.Args) < 3 {
printUsage()
os.Exit(-1)
printHelp()
os.Exit(0)
}

fn := os.Args[1]
Expand Down Expand Up @@ -76,11 +87,12 @@ func main() {
}
}

func printUsage() {
usage := `nv %s — context specific environment variables
Usage: nv <env files> <command> [arguments...]
`
fmt.Printf(usage, build.Version)
func printHelp() {
fmt.Printf("usage: nv <env files> <command> [arguments...]\n")
}

func printVersion() {
fmt.Printf("nv version %s\n", build.Version)
}

func setEnvVars(vars map[string]string) {
Expand Down

0 comments on commit ffab879

Please sign in to comment.