From 0d016129a425d7014c5b8e2ec8eea50962f9ede3 Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Sat, 7 May 2022 14:33:57 -0600 Subject: Implement import-posts script --- srv/src/cfg/cfg.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'srv/src/cfg/cfg.go') 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 +// " " +// +// // Mixed +// " [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 { -- cgit v1.2.3