-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e3a6ecf
commit 6737e9c
Showing
3 changed files
with
78 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package pflag | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/jaffee/commandeer" | ||
"github.com/spf13/pflag" | ||
) | ||
|
||
// Validate interface | ||
var _ = commandeer.FlagNamer(&FlagSet{}) | ||
|
||
// FlagSet is an extension to *pflag.FlagSet that satisfies FlagNamer | ||
type FlagSet struct { | ||
*pflag.FlagSet | ||
} | ||
|
||
// Flags returns a slice of flag names | ||
func (f *FlagSet) Flags() (flags []string) { | ||
f.VisitAll(func(f *pflag.Flag) { | ||
flags = append(flags, f.Name) | ||
}) | ||
return flags | ||
} | ||
|
||
// LoadEnv calls LoadArgsEnv with args from the command line and the | ||
// default flag set. | ||
func LoadEnv(main interface{}, envPrefix string, parseElsewhere func(main interface{}) error) error { | ||
return commandeer.LoadArgsEnv(&FlagSet{pflag.CommandLine}, main, os.Args[1:], envPrefix, parseElsewhere) | ||
} |