Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help subcommand #158

Open
coolaj86 opened this issue Oct 24, 2023 · 4 comments
Open

help subcommand #158

coolaj86 opened this issue Oct 24, 2023 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@coolaj86
Copy link
Contributor

coolaj86 commented Oct 24, 2023

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.

@mohammed90
Copy link
Member

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

@mohammed90 mohammed90 added enhancement New feature or request good first issue Good for newcomers labels Oct 24, 2023
@coolaj86
Copy link
Contributor Author

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

@francislavoie
Copy link
Member

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.

@millette
Copy link

See also #174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants