aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/options/options.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/internal/options/options.go b/internal/options/options.go
new file mode 100644
index 0000000..bfe16a2
--- /dev/null
+++ b/internal/options/options.go
@@ -0,0 +1,31 @@
+package options
+
+import (
+ "flag"
+ "os"
+)
+
+func Parse(usage func(), set func(*flag.FlagSet)) *flag.FlagSet {
+ args := os.Args
+ if len(args) < 2 {
+ args = append(args, "")
+ }
+
+ fs := flag.NewFlagSet(args[1], flag.ExitOnError)
+ fs.Usage = func() {
+ usage()
+ }
+ set(fs)
+ fs.Parse(args[2:])
+ return fs
+}
+
+func AddString(fs *flag.FlagSet, opt *string, short, long, value string) {
+ fs.StringVar(opt, short, value, "")
+ fs.StringVar(opt, long, value, "")
+}
+
+func AddUint64(fs *flag.FlagSet, opt *uint64, short, long string, value uint64) {
+ fs.Uint64Var(opt, short, value, "")
+ fs.Uint64Var(opt, long, value, "")
+}