From bcfb32b8b0ea078afdd72bed4de03ccd59bea40d Mon Sep 17 00:00:00 2001 From: jszwedko Date: Fri, 11 Jul 2014 18:16:19 -0400 Subject: [PATCH 1/2] Updating tests to pass `go vet` Mostly lack of struct field names in literals and one sprintf format specifier mismatch. --- app_test.go | 6 +++--- cli_test.go | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/app_test.go b/app_test.go index cf0e3d0..9414c1b 100644 --- a/app_test.go +++ b/app_test.go @@ -43,7 +43,7 @@ func ExampleAppSubcommand() { Usage: "sends a greeting in english", Description: "greets someone in english", Flags: []cli.Flag{ - cli.StringFlag{"name", "Bob", "Name of the person to greet"}, + cli.StringFlag{Name: "name", Value: "Bob", Usage: "Name of the person to greet"}, }, Action: func(c *cli.Context) { fmt.Println("Hello,", c.String("name")) @@ -255,11 +255,11 @@ func TestApp_ParseSliceFlags(t *testing.T) { var expectedStringSlice = []string{"8.8.8.8", "8.8.4.4"} if !IntsEquals(parsedIntSlice, expectedIntSlice) { - t.Errorf("%s does not match %s", parsedIntSlice, expectedIntSlice) + t.Errorf("%v does not match %v", parsedIntSlice, expectedIntSlice) } if !StrsEquals(parsedStringSlice, expectedStringSlice) { - t.Errorf("%s does not match %s", parsedStringSlice, expectedStringSlice) + t.Errorf("%v does not match %v", parsedStringSlice, expectedStringSlice) } } diff --git a/cli_test.go b/cli_test.go index 30f3c13..4d7bd84 100644 --- a/cli_test.go +++ b/cli_test.go @@ -1,8 +1,9 @@ package cli_test import ( - "github.com/codegangsta/cli" "os" + + "github.com/codegangsta/cli" ) func Example() { @@ -47,7 +48,7 @@ func ExampleSubcommand() { Usage: "sends a greeting in english", Description: "greets someone in english", Flags: []cli.Flag{ - cli.StringFlag{"name", "Bob", "Name of the person to greet"}, + cli.StringFlag{Name: "name", Value: "Bob", Usage: "Name of the person to greet"}, }, Action: func(c *cli.Context) { println("Hello, ", c.String("name")) @@ -57,7 +58,7 @@ func ExampleSubcommand() { ShortName: "sp", Usage: "sends a greeting in spanish", Flags: []cli.Flag{ - cli.StringFlag{"surname", "Jones", "Surname of the person to greet"}, + cli.StringFlag{Name: "surname", Value: "Jones", Usage: "Surname of the person to greet"}, }, Action: func(c *cli.Context) { println("Hola, ", c.String("surname")) @@ -67,7 +68,7 @@ func ExampleSubcommand() { ShortName: "fr", Usage: "sends a greeting in french", Flags: []cli.Flag{ - cli.StringFlag{"nickname", "Stevie", "Nickname of the person to greet"}, + cli.StringFlag{Name: "nickname", Value: "Stevie", Usage: "Nickname of the person to greet"}, }, Action: func(c *cli.Context) { println("Bonjour, ", c.String("nickname")) From c99454b374ae684d01fb654b41d82c2c2584a38d Mon Sep 17 00:00:00 2001 From: jszwedko Date: Fri, 11 Jul 2014 18:17:30 -0400 Subject: [PATCH 2/2] Adding struct field names to examples in README Idiomatic Go --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4621310..59806f4 100644 --- a/README.md +++ b/README.md @@ -137,7 +137,7 @@ Setting and querying flags is simple. ``` go ... app.Flags = []cli.Flag { - cli.StringFlag{"lang", "english", "language for the greeting"}, + cli.StringFlag{Name: "lang", Value: "english", Usage: "language for the greeting"}, } app.Action = func(c *cli.Context) { name := "someone" @@ -159,7 +159,7 @@ You can set alternate (or short) names for flags by providing a comma-delimited ``` go app.Flags = []cli.Flag { - cli.StringFlag{"lang, l", "english", "language for the greeting"}, + cli.StringFlag{Name: "lang, l", Value: "english", Usage: "language for the greeting"}, } ```