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

[SR-7831] ArgumentParser parses short option and option-argument without delimiting space as a single (likely unrecognised) option #4800

Open
ankitspd opened this issue May 31, 2018 · 6 comments
Labels
bug good first issue Good for newcomers Edit

Comments

@ankitspd
Copy link
Member

Previous ID SR-7831
Radar rdar://problem/36340481
Original Reporter @aciidb0mb3r
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Package Manager
Labels Bug, StarterBug
Assignee None
Priority Medium

md5: 96d5acc7cd3ec4326fc64597be212962

Issue Description:

`ArgumentParser` parses short option and option-argument without delimiting space as a single (likely unrecognised) option.

For example, if an option is added to the parser with a short name of `-n`, `ArgumentParser` parses `-n 2` as the “n” option with “2” as its option-argument.

But it parses `-n2` as the unknown option `n2`.

Where long options are prefixed with `--`, it is common for CLI to treat `-n2` and `-n 2` identically.

This probably also implies `ArgumentParser` doesn’t handle adjoining flags (e.g. parsing `-abc` identically to `-a -b -c`) — but I haven’t tested this.

@swift-ci
Copy link
Contributor

Comment by Shai Mishali (JIRA)

Not sure this is necessarily a correct fix, since `swift -help` and `swift --help` both work.
Meaning, SwiftPM long runtime argument aren't limited to using `--`. (in our case it would be equal to -h -e -l -p, which you probably don't want)

Would love to know what you think @aciidb0mb3r

@ankitspd
Copy link
Member Author

I think we can make it work for the options that have a short option declared so it misinterpret options that have a single dash.

@swift-ci
Copy link
Contributor

Comment by Shai Mishali (JIRA)

I think accepting `-n2` is easily achievable but accepting `-abc` is much harder, since `-abc` could also be a long option (e.g. if you do `-heyx`, is it `-h -e -y -x`? it is `-hey -x` ? That's sort of what I'm wondering.

Interested in trying to tackle but not sure what's the intended behavior here

@belkadan
Copy link

Resetting assignee for all Starter Bugs not touched since 2018.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 4, 2022
@tomerd tomerd added good first issue Good for newcomers Edit and removed Package Manager labels May 14, 2022
@MaxDesiatov
Copy link
Member

MaxDesiatov commented Nov 18, 2022

Should this be moved to the ArgumentParser repository? It doesn't seem to be specific to SwiftPM.

@tomerd
Copy link
Member

tomerd commented Nov 18, 2022

yes if its still a problem

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

No branches or pull requests

5 participants