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

Add -? as a flag for help #121

Open
burhan opened this issue Feb 7, 2024 · 8 comments
Open

Add -? as a flag for help #121

burhan opened this issue Feb 7, 2024 · 8 comments

Comments

@burhan
Copy link

burhan commented Feb 7, 2024

-? is a common flag for help

@eqn-group
Copy link

eqn-group commented Mar 21, 2024

I think we should reserve some flags, and it will be applicable for all the programs except legacy ones.
-h or --help should must print help and it can be used even in ls cd commands, any program should output help only when -h or --help is given as argument, and it shouldn't be mixed with other arguments except where applicable.

If your program does nothing without any arguments, it can be left to program author what to return if no arguments are provided in command line, but help must only be printed when -h or --help is supplied.

Or,
another extension to this could be--> some programs are complex and do computationally heavy and sensitive operations.
so i think programs without command line arguments should be illegal. Assign a reserved argument like -r (run) to run normally. when invoked without -r flag just return 0;. (an exception to this could be common two letters unix programs like ls, cd) which requires quick use by the user, and this system could be added through configure script for that program.

for e.g. lets say unix ls command will only run if supplied with -r flag, so it will print directors when invoked like ls -r, but if you want to go back to default for power user, this can be omitted from its config script or environment variable, env variable is better so ls will run then without -r.

@thiagola92
Copy link

I never saw -? for help, it's really common?

@wookietreiber
Copy link

wookietreiber commented Apr 16, 2024

I never saw -? for help, it's really common?

Not that I'm a huge maintainer/contributor in CLI apps 😅 but I have some out there and I'm using -? over -h for short help output in all my tools, right from the start. -? clearly indicates a question / asking for help, while, although situational, -h might be a more suitable abbreviation for something else, most notably in network-related tools for --host. In case I later figure out that I'd need -h for something else, I'd need to deprecate it first or do a hard switch with the CLI or that I'd have to use a less appropriate short version, which are both unfortunate situations. So I decided, at least for myself, to use -? for help, always and right from the start.

@aanand
Copy link
Contributor

aanand commented Apr 16, 2024

Not weighing in on the -? question (which I don't have a strong opinion about), I just want to address this:

-h might be a more suitable abbreviation for something else, most notably in network-related tools for --host. In case I later figure out that I'd need -h for something else, I'd need to deprecate it first or do a hard switch with the CLI or that I'd have to use a less appropriate short version

It's ultimately up to you, but the guidelines directly advise against this in a couple of places ("Don't overload -h"; "-h... should only mean help"). Users of your tools will expect -h to mean "help", because it's a de facto standard. I've tripped up on docker run -h many times for this exact reason.

@wookietreiber
Copy link

Not weighing in on the -? question (which I don't have a strong opinion about), I just want to address this:

-h might be a more suitable abbreviation for something else, most notably in network-related tools for --host. In case I later figure out that I'd need -h for something else, I'd need to deprecate it first or do a hard switch with the CLI or that I'd have to use a less appropriate short version

It's ultimately up to you, but the guidelines directly advise against this in a couple of places ("Don't overload -h"; "-h... should only mean help"). Users of your tools will expect -h to mean "help", because it's a de facto standard. I've tripped up on docker run -h many times for this exact reason.

whoopsie 😅

@burhan
Copy link
Author

burhan commented Apr 18, 2024

There are some other considerations, and there isn't a defined standard, but lots of guidelines:

The documentation for getopt() states

If getopt() encounters an option character that is not contained in optstring, it shall return the ( '?' ) character. If it detects a missing option-argument, it shall return the character ( ':' ) if the first character of optstring was a , or a character ( '?' ) otherwise.

I'm assuming this is where this de-facto standard came in. As ? is returned by getopt() for unrecognized options, -? became a way to list all options, rather than failing silently. It is unlikely that -? would be a common option, unlike -h which could mean an actual option. The most common one I know is -h for --human-readable for ls.

I think its good to add this in and say that along with -h & --help, -? can be used to print usage or help documentation.

@eqn-group
Copy link

eqn-group commented Apr 18, 2024 via email

@tashian
Copy link
Member

tashian commented May 2, 2024

Hey @burhan, thanks for doing some research on this for us!

I have a pretty strong point of view about this.

With CLI Guidlines, we are asking the question:
If you are building a new tool today, from scratch, what should you do?

And, I do not think -? should be implemented as a help flag for new CLI apps today.
I think we should stick to the GNU standard here: --help is ideal.

However, if an unknown flag is passed in, help should be displayed.
Practically speaking, this will mean that -? displays help.
But, we should not explicitly recommend -? as a help flag.
I think it should be reserved, but not documented.

Some background

I think the reason we have --help is because -h has been overloaded, so --help (or help) is more reliable.
Unfortunately, ls can't change how -h behaves. It is set in stone at this point.
The fact that older tools—and even docker—have overloaded -h is annoying in the same way we have strange exceptions to grammar rules in English.

Meanwhile, there's -?.
I think of -? as a legacy flag that should not be introduced in new applications.
Applications that initially used -? or -h have had to later adopt --help, but not vice versa.

I think the MS standard that mentions -? is tailored to PowerShell programs, and isn't relevant here. PowerShell/Windows has a lot of different conventions from UNIX and is beyond the scope of CLI Guidelines.

When I was poking around for examples just now, I noticed that the fish shell treats -? as a wildcard:

fish$ zip -?
fish: No matches for wildcard '-?'. See `help wildcards-globbing`.
zip -?
    ^^

So, -? doesn't even work in fish. More evidence, in my view, that the world is moving away from -?.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants