summaryrefslogtreecommitdiff
path: root/srv/src/cfg/cfg.go
diff options
context:
space:
mode:
authorBrian Picciano <mediocregopher@gmail.com>2022-05-07 14:33:57 -0600
committerBrian Picciano <mediocregopher@gmail.com>2022-05-07 14:33:57 -0600
commit0d016129a425d7014c5b8e2ec8eea50962f9ede3 (patch)
tree29adbde9edb432fab24f16d0211c06abe3eba93f /srv/src/cfg/cfg.go
parenta10a604018d0cb07babfe218d9fb2e00e1c8ae3b (diff)
Implement import-posts script
Diffstat (limited to 'srv/src/cfg/cfg.go')
-rw-r--r--srv/src/cfg/cfg.go34
1 files changed, 34 insertions, 0 deletions
diff --git a/srv/src/cfg/cfg.go b/srv/src/cfg/cfg.go
index 8513e16..32fc3e7 100644
--- a/srv/src/cfg/cfg.go
+++ b/srv/src/cfg/cfg.go
@@ -130,6 +130,40 @@ func (c *Cfg) StringVar(p *string, name, value, usage string) {
}
}
+// Args returns a pointer which will be filled with the process's positional
+// arguments after Init is called. The positional arguments are all CLI
+// arguments starting with the first non-flag argument.
+//
+// The usage argument should describe what these arguments are, and its notation
+// should indicate if they are optional or variadic. For example:
+//
+// // optional variadic
+// "[names...]"
+//
+// // required single args
+// "<something> <something else>"
+//
+// // Mixed
+// "<foo> <bar> [baz] [other...]"
+//
+func (c *Cfg) Args(usage string) *[]string {
+
+ args := new([]string)
+
+ c.flagSet.Usage = func() {
+ fmt.Fprintf(os.Stderr, "USAGE [flags...] %s\n", usage)
+ fmt.Fprintf(os.Stderr, "\nFLAGS\n\n")
+ c.flagSet.PrintDefaults()
+ }
+
+ c.OnInit(func(ctx context.Context) error {
+ *args = c.flagSet.Args()
+ return nil
+ })
+
+ return args
+}
+
// String is equivalent to flag.FlagSet's String method, but will additionally
// set up an environment variable for the parameter.
func (c *Cfg) String(name, value, usage string) *string {