rednafi / httpurr

ᗢ HTTP status codes on speed dial
MIT License
20 stars 2 forks source link

GoLang supports double dash flags #13

Closed lil5 closed 1 year ago

lil5 commented 1 year ago

This should already work with the current code, I suggest changing the documentation to advise people to use double dashes.

A consideration can be made to have short form flags too.

var verbose bool
flag.BoolVar(&verbose, "verbose", false, "verbose output")
flag.BoolVar(&verbose, "v", false, "verbose output")
flag.Parse()
if verbose {
    fmt.Println("verbose is on")
}
$ ./using_flag -v
verbose is on
$ ./using_flag --verbose
verbose is on
$ ./using_flag --v
verbose is on
$ ./using_flag -verbose
verbose is on

Source: https://www.antoniojgutierrez.com/posts/2021-05-14-short-and-long-options-in-go-flags-pkg/

rednafi commented 1 year ago

I learned a new thing. I like the idea of having short flags. Regarding the --, is there a reason why -- might be better than -? I've seen that maximum Go CLIs show example with a single dash.

Mind creating a PR? The tests need to be updated to check the short flags as well. Or I'll take a look at it soon. Thanks!

lil5 commented 1 year ago

Double dash flags are normally used to differentiate between a collection of short flags and a single flag rsync -rlptgoD vs rsync --archive. GoLang flags is the exception to use -archive but will see -av as a single flag not -a & -v put together.

Because of this I use "github.com/urfave/cli/v2" for my go cli's which work like most expect a cli to work but I can understand if you don't want to add a dependency.

Example: https://cli.urfave.org/v2/examples/flags/

Mind creating a PR

I'll do so once a I know how to continue.

rednafi commented 1 year ago

@lil5 let's keep it simple and not add the dependency first. I like the idea of having one letter short flags; just didn't know how to do that in Go.