From 5800b89ce9817f99b805776fe86046e2a26dc536 Mon Sep 17 00:00:00 2001 From: Alex Flint Date: Sun, 31 Jul 2016 09:14:44 -0700 Subject: [PATCH] fix example function names --- example_test.go | 12 ++++++------ parse.go | 6 +++--- parse_test.go | 16 +++++++++++----- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/example_test.go b/example_test.go index bdba6ac..6fb5197 100644 --- a/example_test.go +++ b/example_test.go @@ -6,7 +6,7 @@ import ( ) // This example demonstrates basic usage -func Example_Basic() { +func Example() { // These are the args you would pass in on the command line os.Args = []string{"./example", "--foo=hello", "--bar"} @@ -19,7 +19,7 @@ func Example_Basic() { } // This example demonstrates arguments that have default values -func Example_DefaultValues() { +func Example_defaultValues() { // These are the args you would pass in on the command line os.Args = []string{"--help"} @@ -33,7 +33,7 @@ func Example_DefaultValues() { } // This example demonstrates arguments that are required -func Example_RequiredArguments() { +func Example_requiredArguments() { // These are the args you would pass in on the command line os.Args = []string{"--foo=1", "--bar"} @@ -45,7 +45,7 @@ func Example_RequiredArguments() { } // This example demonstrates positional arguments -func Example_PositionalArguments() { +func Example_positionalArguments() { // These are the args you would pass in on the command line os.Args = []string{"./example", "in", "out1", "out2", "out3"} @@ -59,7 +59,7 @@ func Example_PositionalArguments() { } // This example demonstrates arguments that have multiple values -func Example_MultipleValues() { +func Example_multipleValues() { // The args you would pass in on the command line os.Args = []string{"--help"} @@ -72,7 +72,7 @@ func Example_MultipleValues() { } // This example shows the usage string generated by go-arg -func Example_UsageString() { +func Example_usageString() { // These are the args you would pass in on the command line os.Args = []string{"--help"} diff --git a/parse.go b/parse.go index b08a298..b1193d0 100644 --- a/parse.go +++ b/parse.go @@ -95,8 +95,8 @@ func NewParser(config Config, dests ...interface{}) (*Parser, error) { // Check whether this field is supported. It's good to do this here rather than // wait until setScalar because it means that a program with invalid argument - // fields will always fail regardless of whether the arguments it recieved happend - // to exercise those fields. + // fields will always fail regardless of whether the arguments it received + // exercised those fields. var parseable bool parseable, spec.boolean, spec.multiple = canParse(field.Type) if !parseable { @@ -309,7 +309,7 @@ func validate(spec []*spec) error { return nil } -// parse a value as the apropriate type and store it in the struct +// parse a value as the appropriate type and store it in the struct func setSlice(dest reflect.Value, values []string) error { if !dest.CanSet() { return fmt.Errorf("field is not writable") diff --git a/parse_test.go b/parse_test.go index 8ee6a79..ab0cfd7 100644 --- a/parse_test.go +++ b/parse_test.go @@ -12,6 +12,12 @@ import ( "github.com/stretchr/testify/require" ) +func setenv(t *testing.T, name, val string) { + if err := os.Setenv(name, val); err != nil { + t.Error(err) + } +} + func parse(cmdline string, dest interface{}) error { p, err := NewParser(Config{}, dest) if err != nil { @@ -453,7 +459,7 @@ func TestEnvironmentVariable(t *testing.T) { var args struct { Foo string `arg:"env"` } - os.Setenv("FOO", "bar") + setenv(t, "FOO", "bar") os.Args = []string{"example"} MustParse(&args) assert.Equal(t, "bar", args.Foo) @@ -463,7 +469,7 @@ func TestEnvironmentVariableOverrideName(t *testing.T) { var args struct { Foo string `arg:"env:BAZ"` } - os.Setenv("BAZ", "bar") + setenv(t, "BAZ", "bar") os.Args = []string{"example"} MustParse(&args) assert.Equal(t, "bar", args.Foo) @@ -473,7 +479,7 @@ func TestEnvironmentVariableOverrideArgument(t *testing.T) { var args struct { Foo string `arg:"env"` } - os.Setenv("FOO", "bar") + setenv(t, "FOO", "bar") os.Args = []string{"example", "--foo", "baz"} MustParse(&args) assert.Equal(t, "baz", args.Foo) @@ -483,7 +489,7 @@ func TestEnvironmentVariableError(t *testing.T) { var args struct { Foo int `arg:"env"` } - os.Setenv("FOO", "bar") + setenv(t, "FOO", "bar") os.Args = []string{"example"} err := Parse(&args) assert.Error(t, err) @@ -493,7 +499,7 @@ func TestEnvironmentVariableRequired(t *testing.T) { var args struct { Foo string `arg:"env,required"` } - os.Setenv("FOO", "bar") + setenv(t, "FOO", "bar") os.Args = []string{"example"} MustParse(&args) assert.Equal(t, "bar", args.Foo)