Fix various linting warnings
diff --git a/command.go b/command.go
index a30f560..aab34e6 100644
--- a/command.go
+++ b/command.go
@@ -112,9 +112,9 @@
return nil
}
-// Find an option that is part of the command, or any of its
-// parent commands, by matching its long name
-// (including the option namespace).
+// FindOptionByLongName finds an option that is part of the command, or any of
+// its parent commands, by matching its long name (including the option
+// namespace).
func (c *Command) FindOptionByLongName(longName string) (option *Option) {
for option == nil && c != nil {
option = c.Group.FindOptionByLongName(longName)
@@ -125,9 +125,9 @@
return option
}
-// Find an option that is part of the command, or any of its
-// parent commands, by matching its long name
-// (including the option namespace).
+// FindOptionByShortName finds an option that is part of the command, or any of
+// its parent commands, by matching its long name (including the option
+// namespace).
func (c *Command) FindOptionByShortName(shortName rune) (option *Option) {
for option == nil && c != nil {
option = c.Group.FindOptionByShortName(shortName)
diff --git a/example_test.go b/example_test.go
index f7be2bb..4321ed8 100644
--- a/example_test.go
+++ b/example_test.go
@@ -41,7 +41,7 @@
// Example of positional arguments
Args struct {
- Id string
+ ID string
Num int
Rest []string
} `positional-args:"yes" required:"yes"`
@@ -92,7 +92,7 @@
fmt.Printf("PtrSlice: [%v %v]\n", *opts.PtrSlice[0], *opts.PtrSlice[1])
fmt.Printf("IntMap: [a:%v b:%v]\n", opts.IntMap["a"], opts.IntMap["b"])
fmt.Printf("Filename: %v\n", opts.Filename)
- fmt.Printf("Args.Id: %s\n", opts.Args.Id)
+ fmt.Printf("Args.ID: %s\n", opts.Args.ID)
fmt.Printf("Args.Num: %d\n", opts.Args.Num)
fmt.Printf("Args.Rest: %v\n", opts.Args.Rest)
@@ -104,7 +104,7 @@
// PtrSlice: [hello world]
// IntMap: [a:1 b:5]
// Filename: hello.go
- // Args.Id: id
+ // Args.ID: id
// Args.Num: 10
// Args.Rest: [remaining1 remaining2]
}
diff --git a/group.go b/group.go
index 6472420..b1ef6ed 100644
--- a/group.go
+++ b/group.go
@@ -110,16 +110,16 @@
return option
}
-// Find an option that is part of the group, or any of its subgroups,
-// by matching its long name (including the option namespace).
+// FindOptionByLongName finds an option that is part of the group, or any of its
+// subgroups, by matching its long name (including the option namespace).
func (g *Group) FindOptionByLongName(longName string) *Option {
return g.findOption(func(option *Option) bool {
return option.LongNameWithNamespace() == longName
})
}
-// Find an option that is part of the group, or any of its subgroups,
-// by matching its short name.
+// FindOptionByShortName finds an option that is part of the group, or any of
+// its subgroups, by matching its short name.
func (g *Group) FindOptionByShortName(shortName rune) *Option {
return g.findOption(func(option *Option) bool {
return option.ShortName == shortName
diff --git a/parser_test.go b/parser_test.go
index d82fe35..9f527b7 100644
--- a/parser_test.go
+++ b/parser_test.go
@@ -215,28 +215,33 @@
}
}
-// envRestorer keeps a copy of a set of env variables and can restore the env from them
-type envRestorer struct {
+// EnvRestorer keeps a copy of a set of env variables and can restore the env from them
+type EnvRestorer struct {
env map[string]string
}
-func (r *envRestorer) Restore() {
+func (r *EnvRestorer) Restore() {
os.Clearenv()
+
for k, v := range r.env {
os.Setenv(k, v)
}
}
// EnvSnapshot returns a snapshot of the currently set env variables
-func EnvSnapshot() *envRestorer {
- r := envRestorer{make(map[string]string)}
+func EnvSnapshot() *EnvRestorer {
+ r := EnvRestorer{make(map[string]string)}
+
for _, kv := range os.Environ() {
parts := strings.SplitN(kv, "=", 2)
+
if len(parts) != 2 {
panic("got a weird env variable: " + kv)
}
+
r.env[parts[0]] = parts[1]
}
+
return &r
}