Skip to content

Commit

Permalink
fix: fix the bug which '-v' option was ignored
Browse files Browse the repository at this point in the history
  • Loading branch information
tamada committed May 15, 2023
1 parent 725d688 commit a701ad7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 12 additions & 0 deletions cmd/urleap/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import (

const VERSION = "0.1.16"

func versionString(args []string) string {
prog := "urleap"
if len(args) > 0 {
prog = filepath.Base(args[0])
}
return fmt.Sprintf("%s version %s", prog, VERSION)
}

/*
helpMessage prints the help message.
This function is used in the small tests, so it may be called with a zero-length slice.
Expand Down Expand Up @@ -106,6 +114,10 @@ func parseOptions(args []string) (*options, []string, *UrleapError) {
fmt.Println(helpMessage(args))
return nil, nil, &UrleapError{statusCode: 0, message: ""}
}
if opts.flagSet.versionFlag {
fmt.Println(versionString(args))
return nil, nil, &UrleapError{statusCode: 0, message: ""}
}
if opts.token == "" {
return nil, nil, &UrleapError{statusCode: 3, message: "no token was given"}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/urleap/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Example_Help() {
}

func Test_Main(t *testing.T) {
if status := goMain([]string{"./urleap", "-t", "token"}); status != 0 {
if status := goMain([]string{"./urleap", "-v"}); status != 0 {
t.Error("Expected 0, got ", status)
}
}

0 comments on commit a701ad7

Please sign in to comment.