xcaddy icon indicating copy to clipboard operation
xcaddy copied to clipboard

`help` subcommand

Open coolaj86 opened this issue 2 years ago • 4 comments

I'd be be just as happy if the first version of the help did nothing more than print the URL to this repo's README, however, it shouldn't fail.

Personally, I often sidestep the flag parser and have POSIX, BSD, and Go-style for help and version, like this:

	if len(os.Args) > 1 {
		// `version`, `-version`, `--version`, `-V`
		if ("version" == strings.TrimLeft(os.Args[1], "-") || "-V" == os.Args[1]) {
			printVersion()
			os.Exit(0)
			return
		}
	}

	if len(os.Args) > 1 {
		// `help`, `-help`, `--help`,
		if ("help" == strings.TrimLeft(os.Args[1], "-")) {
			printHelp()
			os.Exit(0)
			return
		}
	}

That way it meets everyone's expectations and costs nothing in complexity (though sometimes help may need to come after some sort of flag package has parsed all the things... or just `long string` it.

coolaj86 avatar Oct 24 '23 18:10 coolaj86

Actually I'm considering using Cobra. That requires extensive effort to retrofit.

mohammed90 avatar Oct 24 '23 18:10 mohammed90

That seems way overkill. This has two subcommands and two flags. Why bring in those deps when the standard library will do?

coolaj86 avatar Oct 24 '23 19:10 coolaj86

Cobra would let us generate man pages and whatnot which help with packaging. It's also a nicer API to write against. It's a slim dependency now (compared to a couple years ago which necessitated https://github.com/spf13/viper) so IMO no harm bringing it in to make UX easier and more consistent in addition to the extra features it provides.

francislavoie avatar Dec 18 '23 20:12 francislavoie

See also https://github.com/caddyserver/xcaddy/pull/174

millette avatar May 15 '24 03:05 millette