-
Notifications
You must be signed in to change notification settings - Fork 3
better cli arg parsing #69
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
Open
PhilipDeegan
wants to merge
3
commits into
master
Choose a base branch
from
next
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+50
−9
Open
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quoted substring overwrites existing token and drops empty quoted args.
arg = cmd.substr(i, pos)discards any prefix, so inputs likefoo"bar"yield"bar", and thearg.size()check drops empty""args. This is a regression vs. the prior char-by-char behavior.🐛 Proposed fix
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
look at the test, is there some strings you can suggest that are considered valid for command line argument parsing?
really what I'm trying to fix is the following not working
process.run("python3", "-c", "\"import sys; print('lol ' +dir(sys))\"")There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Length of output: 393
@PhilipDeeganHere are comprehensive test strings for CLI argument parsing that would validate your implementation:For your specific Python case:
When the third argument (
"\"import sys; print('lol ' +dir(sys))\"") is parsed byasArgs, it should produce:"..."are just Python string delimiters (not parsed by asArgs)\"become literal"characters in the input string"import sys; print('lol ' +dir(sys))"import sys; print('lol ' +dir(sys))Note: The bug I flagged earlier (using
arg = cmd.substr(...)instead ofarg += cmd.substr(...)) will cause Test 4 and Test 10 to fail because any content before the opening quote gets discarded. This will also affect your Python case if there's any prefix before quotes.Would you like me to help create a comprehensive test suite with all these cases?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh really?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
@PhilipDeeganYes! Let me demonstrate the bug with a concrete test case:This will show that your specific Python case does work (because it starts with a quote), but the bug manifests in other valid CLI scenarios where content precedes the opening quote or when quotes are empty.
🏁 Script executed:
Length of output: 43
🏁 Script executed:
Length of output: 1661
@PhilipDeeganThere you go! The demonstration shows:Your specific Python case works fine ✓
But the bug exists in other valid CLI scenarios:
foo"bar"→ produces['bar']instead of['foobar']prefix"quoted part"→ produces['quoted part']instead of['prefixquoted part']cmd "" arg→ produces['cmd', 'arg']instead of['cmd', '', 'arg']The trace-through shows exactly where it happens: when the parser encounters
foo"bar", it accumulates "foo" intoarg, then when it hits the opening quote and processes the quoted section, it doesarg = cmd.substr(...)which overwrites the "foo" with just "bar".Why it matters: Your use case happens to work because the quotes start at the beginning of each token (after spaces), so there's nothing in
argto overwrite. But a general CLI parser should handle all these cases correctly - shells do support things likeecho foo"bar"bazwhich producesfoobarbaz.Would you like me to suggest the fix, or are these edge cases acceptable for your use case?