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

docs: clarify short options hopefully coming #48

Merged
merged 3 commits into from
Feb 4, 2022

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented Jan 24, 2022

We do not want -foo to be the same as --foo. That much is fairly certain.

-foo is likely to be the same as -f -o -o, at least when plain flags. But nothing implemented yet, so point to issue rather than speculate.

See #2

@bcoe bcoe requested a review from darcyclarke February 2, 2022 16:44
@@ -195,8 +195,7 @@ const { flags, values, positionals } = parseArgs(argv, options);
- Does the API specify whether a `--` was present/relevant?
- no
- Is `-foo` the same as `--foo`?
- yes <-- ! kind of a blocker for shortopts !
- Recommend: "No, -foo is shortopts form of --f --o --o" (assuming none are defined, or withValues)
- no, `-foo` is a short option or options (WIP: https://github.com/pkgjs/parseargs/issues/2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iow, -foo must be either -f -o -o or -f oo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or -f -o o.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oof, that sounds like a horrific result, because how would i know at a glance what it means if that were a possibility?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a common or encouraged usage. But it is a possibility.

In this scenario the person who wrote the command invocation knows that -o takes a value. They know that you may put the value directly after the short option. They know that you may combine short options. (And if they did this in a script then apparently they don't care about the readability and maintainability!)

It might look more reasonable with a progression, and one feature at a time:

start --verbose --port 80
start -v -p 80
start -v -p80
start -vp80

Real world example:

% tar -xff
tar: Error opening archive: Failed to open 'f'

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That combination of obscure knowledge doesn't seem worth it to me to be able to do -xff instead of being forced to add a space and a dash (-x -ff).

Copy link
Member

@ljharb ljharb Feb 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is -f o -o any different than -f -o o? The order shouldn't matter for this scenario, only if f or o, respectively, is declared withValue.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we should make the example is -bar the same as --bar, so there isn't confusion due to the oo.

I think in both cases it should be: -b -a -r, and -f -o -o, and the multiple os would just clobber each other.

We could eventually consider adding support for multiples so that -o, -o would be o: 2, but I think this also supports the -f, -o, -o, interpretation.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Less issues with --bar but the key point is the answer is now "no". That is a step forward for the README!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bcoe i'm 100% fine with what you think it should be in that comment. I found "-bar could be -b a -r or -b -a r, no matter how they're configured, both to be unacceptable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do some fresh exploration on potential -bar equivalence to -b -a r. I went deep on this a couple of years ago because of bugs reported against Commander which at the time did a blind expansion of -foo to-f -o -o, and separately requests and PR for support for -p80. So I have been here before.

@shadowspawn
Copy link
Collaborator Author

Thanks reviewers. I will merge this weekend if nothing else comes up.

@shadowspawn shadowspawn merged commit ab6d1cc into pkgjs:main Feb 4, 2022
@shadowspawn shadowspawn deleted the feature/short-groups-wip branch February 4, 2022 05:23
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

Successfully merging this pull request may close these issues.

4 participants