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

Throw for unsupported option setup #2270

Merged

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented Oct 29, 2024

Pull Request

Problem

People who try and use unsupported Option flags do not get an error, and have to discover themselves that there are problems at runtime.

Placeholder issue: #2235
See: #430 #479 #908 #1718 #1862 #2211 #2222 #2227

Solution

Throw for unsupported Option flags, especially for known issues — too many flags, and short flag with more than one character.

This will break some existing programs that had undetected problems. (It broke one of our tests!)

ChangeLog

  • breaking: throw during Option construction for unsupported option flags

@shadowspawn shadowspawn added the semver: major Releasing requires a major version bump, not backwards compatible label Oct 29, 2024
@shadowspawn shadowspawn added the pending release Merged into a branch for a future release, but not released yet label Oct 29, 2024
@shadowspawn shadowspawn merged commit 966720a into tj:release/13.x Oct 29, 2024
9 checks passed
@shadowspawn shadowspawn deleted the feature/stricter-option-flags branch October 29, 2024 08:34
@shadowspawn shadowspawn removed the pending release Merged into a branch for a future release, but not released yet label Dec 30, 2024
@shadowspawn
Copy link
Collaborator Author

Released in Commander v13.0.0

@p3k
Copy link

p3k commented Jan 8, 2025

Hi @shadowspawn! We noticed some of our commands break with v13 because they are configured with more than one long flag. The idea is to provide a shorter version without using a one-letter option, e.g. --es and --ecmascript or --ddsg and --donaudampfschifffahrtsgesellschaft (just kidding with the latter one).

Now that multi-letter options are also throwing an error, this feels quite limiting. I get the point of considering POSIX-compatibility with multi-letter options (I am always confused by those e.g. in Gnu’s find command) – does the same apply to multiple long flags or did you have other considerations?

@shadowspawn
Copy link
Collaborator Author

No, I had not considered multiple long options. Like multi-character short options, they just happened to work. There is an issue open about multiple-character short options, and I'll add a reference to multiple longs: #2307

Hyrum's Law: https://www.hyrumslaw.com

With a sufficient number of users of an API,
it does not matter what you promise in the contract:
all observable behaviors of your system
will be depended on by somebody.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver: major Releasing requires a major version bump, not backwards compatible
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants