summaryrefslogtreecommitdiff
path: root/commandline.go
diff options
context:
space:
mode:
authorEthel Morgan <eth@ethulhu.co.uk>2020-06-24 12:10:57 +0100
committerEthel Morgan <eth@ethulhu.co.uk>2020-06-24 12:10:57 +0100
commitaa380da6a61f9b29ee263d95d17a2953a0528b28 (patch)
treec2915f6508ed321eeacb6ca3c7ba8de313c0ce11 /commandline.go
parent02f268cc3ba056be15097a7185a367585dd05275 (diff)
import package flag from helixv0.0.1
Diffstat (limited to 'commandline.go')
-rw-r--r--commandline.go46
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)
+}