diff options
Diffstat (limited to '')
-rw-r--r-- | commandline.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/commandline.go b/commandline.go new file mode 100644 index 0000000..db3d413 --- /dev/null +++ b/commandline.go @@ -0,0 +1,46 @@ +// SPDX-FileCopyrightText: 2020 Ethel Morgan +// +// SPDX-License-Identifier: MIT + +package flag + +import ( + "fmt" + "os" + "time" +) + +var ( + CommandLine = NewFlagSet(os.Args[0], ExitOnError) + Usage = func() { + fmt.Fprintf(CommandLine.Output(), "Usage of %s:\n", os.Args[0]) + CommandLine.PrintDefaults() + } +) + +func init() { + CommandLine.Usage = runUsageVariable +} +func runUsageVariable() { + Usage() +} + +func Parse() { + _ = CommandLine.Parse(os.Args[1:]) +} + +func String(flagName, defaultValue, description string) *string { + return CommandLine.String(flagName, defaultValue, description) +} +func Int(flagName string, defaultValue int, description string) *int { + return CommandLine.Int(flagName, defaultValue, description) +} +func Duration(flagName string, defaultValue time.Duration, description string) *time.Duration { + return CommandLine.Duration(flagName, defaultValue, description) +} +func Custom(flagName, defaultValue, description string, parser ParseFunc) *interface{} { + return CommandLine.Custom(flagName, defaultValue, description, parser) +} +func Bool(flagName string, defaultValue bool, description string) *bool { + return CommandLine.Bool(flagName, defaultValue, description) +} |