Merge pull request #35 from alexflint/fix_example_names

fix example function names
This commit is contained in:
Alex Flint 2016-07-31 09:21:49 -07:00 committed by GitHub
commit a5617823b0
3 changed files with 20 additions and 14 deletions

View File

@ -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"}

View File

@ -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")

View File

@ -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)