-
Notifications
You must be signed in to change notification settings - Fork 10
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
feat!: switch type:string option arguments to greedy, but with error for suspect cases in strict mode #88
Merged
Merged
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a28864d
First cut at greedy with error for suspect value
shadowspawn 831e6da
Fix checkSafeOptionValue
shadowspawn de21b0f
Add some unit tests for new strict error for suspect option value
shadowspawn 2afaebc
Static example usage
shadowspawn 5fe37b7
Tweak parameter names in response to feedback
shadowspawn f9ff015
Merge branch 'main' into feature/greedy
shadowspawn 05967d4
Merge branch 'main' into feature/greedy
shadowspawn a7556dd
Rename routine, use custom error
shadowspawn da9fbcf
Add short example, and use function style matching other PR in flight.
shadowspawn 6439e99
Refactor tests and fix for new short message
shadowspawn ff03bcd
Switch to node compatible test format
shadowspawn bc77eb2
Add end-to-end greedy tests
shadowspawn 3b7ac89
Merge branch 'main' into feature/greedy
shadowspawn 8487167
Move checking routines together
shadowspawn 65c0833
Merge branch 'main' into feature/greedy
shadowspawn 120d95a
Merge remote-tracking branch 'upstream/main' into feature/greedy
shadowspawn 62726b8
Tweak error
shadowspawn 4362750
Go with ambiguous, matches having two informative messages.
shadowspawn 0eac39d
Merge branch 'main' into feature/greedy
shadowspawn f4ceff3
Fix more tests for null prototype
shadowspawn 22745ac
Merge branch 'main' into feature/greedy
bcoe f731241
Merge remote-tracking branch 'upstream/main' into feature/greedy
shadowspawn e477243
Merge branch 'feature/greedy' of github.com:shadowspawn/parseargs int…
shadowspawn 836bd9a
Move greedy related tests into index.js
shadowspawn 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 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 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
'use strict'; | ||
/* eslint max-len: 0 */ | ||
|
||
const test = require('tape'); | ||
const { isOptionLikeValue } = require('../utils.js'); | ||
|
||
// Basically rejecting values starting with a dash, but run through the interesting possibilities. | ||
|
||
test('isOptionLikeValue: when passed plain text then returns false', (t) => { | ||
t.false(isOptionLikeValue('abc')); | ||
t.end(); | ||
}); | ||
|
||
test('isOptionLikeValue: when passed digits then returns false', (t) => { | ||
t.false(isOptionLikeValue(123)); | ||
t.end(); | ||
}); | ||
|
||
test('isOptionLikeValue: when passed empty string then returns false', (t) => { | ||
t.false(isOptionLikeValue('')); | ||
t.end(); | ||
}); | ||
|
||
// Special case, used as stdin/stdout et al and not reason to reject | ||
test('isOptionLikeValue: when passed dash then returns false', (t) => { | ||
t.false(isOptionLikeValue('-')); | ||
t.end(); | ||
}); | ||
|
||
test('isOptionLikeValue: when passed -- then returns true', (t) => { | ||
// Not strictly option-like, but is supect | ||
t.true(isOptionLikeValue('--')); | ||
t.end(); | ||
}); | ||
|
||
// Supporting undefined so can pass element off end of array without checking | ||
test('isOptionLikeValue: when passed undefined then returns false', (t) => { | ||
t.false(isOptionLikeValue(undefined)); | ||
t.end(); | ||
}); | ||
|
||
test('isOptionLikeValue: when passed short option then returns true', (t) => { | ||
t.true(isOptionLikeValue('-a')); | ||
t.end(); | ||
}); | ||
|
||
test('isOptionLikeValue: when passed short option digit then returns true', (t) => { | ||
t.true(isOptionLikeValue('-1')); | ||
t.end(); | ||
}); | ||
|
||
test('isOptionLikeValue: when passed negative number then returns true', (t) => { | ||
t.true(isOptionLikeValue('-123')); | ||
t.end(); | ||
}); | ||
|
||
test('isOptionLikeValue: when passed short option group of short option with value then returns true', (t) => { | ||
t.true(isOptionLikeValue('-abd')); | ||
t.end(); | ||
}); | ||
|
||
test('isOptionLikeValue: when passed long option then returns true', (t) => { | ||
t.true(isOptionLikeValue('--foo')); | ||
t.end(); | ||
}); | ||
|
||
test('isOptionLikeValue: when passed long option with value then returns true', (t) => { | ||
t.true(isOptionLikeValue('--foo=bar')); | ||
t.end(); | ||
}); |
This file contains 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 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.
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.
rather than
-XYZ
, any reason not to make this--${longOption}=${optionValue}
.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.
Short version: Quoting.
I actually had that but then worried about quoting it correctly in all cases, on all platforms, so it would work if copied and pasted. Went for a short safe placeholder!
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.
(I'll have a look for a future PR at using the value in the error message if it is plain text.)