Skip to content

Commit

Permalink
Show version on help
Browse files Browse the repository at this point in the history
  • Loading branch information
int128 committed Sep 5, 2018
1 parent 8b6257d commit 9b325a6
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 4 additions & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ import (
)

// Parse parses command line arguments and returns a CLI instance.
func Parse(osArgs []string) (*CLI, error) {
func Parse(osArgs []string, version string) (*CLI, error) {
var cli CLI
parser := flags.NewParser(&cli, flags.HelpFlag)
parser.LongDescription = fmt.Sprintf(`Version %s
This updates the kubeconfig for Kubernetes OpenID Connect (OIDC) authentication.`,
version)
args, err := parser.ParseArgs(osArgs[1:])
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
)

func TestParse(t *testing.T) {
c, err := Parse([]string{"kubelogin"})
c, err := Parse([]string{"kubelogin"}, "version")
if err != nil {
t.Errorf("Parse returned error: %s", err)
}
Expand All @@ -15,7 +15,7 @@ func TestParse(t *testing.T) {
}

func TestParse_TooManyArgs(t *testing.T) {
c, err := Parse([]string{"kubelogin", "some"})
c, err := Parse([]string{"kubelogin", "some"}, "version")
if err == nil {
t.Errorf("Parse should return error but nil")
}
Expand All @@ -25,7 +25,7 @@ func TestParse_TooManyArgs(t *testing.T) {
}

func TestParse_Help(t *testing.T) {
c, err := Parse([]string{"kubelogin", "--help"})
c, err := Parse([]string{"kubelogin", "--help"}, "version")
if err == nil {
t.Errorf("Parse should return error but nil")
}
Expand Down
5 changes: 4 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import (
"github.com/int128/kubelogin/cli"
)

// Set by goreleaser, see https://goreleaser.com/environment/
var version = "1.x"

func main() {
c, err := cli.Parse(os.Args)
c, err := cli.Parse(os.Args, version)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 9b325a6

Please sign in to comment.