-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Don't choke on switches in --example=VALUE format #6759
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
Changes from 1 commit
2b072f8
1f45c43
279f15e
abad471
d3f75d8
47ed17a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -371,13 +371,25 @@ namespace ts { | |
parseResponseFile(s.slice(1)); | ||
} | ||
else if (s.charCodeAt(0) === CharacterCodes.minus) { | ||
s = s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1).toLowerCase(); | ||
s = s.slice(s.charCodeAt(1) === CharacterCodes.minus ? 2 : 1); | ||
|
||
// Try to translate short option names to their full equivalents. | ||
if (hasProperty(shortOptionNames, s)) { | ||
if (hasProperty(shortOptionNames, s.toLowerCase())) { | ||
s = shortOptionNames[s]; | ||
} | ||
else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's weird that this doesn't work for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right now tsc doesn't really follow anybody's conventions. It's more like an ad-hoc compromise between PowerShell (camelcase flags and space separators for values) and Linux (double dash flags like getopt_long uses). Even though it's not documented, the way it's implemented allows you to go full PowerShell-style and use e.g., |
||
// When using long-form switches, we follow standard command-line conventions and accept | ||
// "--example=VALUE", but we also accept "--example VALUE". | ||
var [ longFormSwitch ] = s.split("=", 1); | ||
if (longFormSwitch.length < s.length && hasProperty(optionNameMap, longFormSwitch.toLowerCase())) { | ||
// It's in "--example=VALUE" format. Replace it in the arg list with the separated format. | ||
var value = s.substring(longFormSwitch.length + 1); | ||
args.splice(i - 1, 1, longFormSwitch, value); | ||
s = longFormSwitch; | ||
} | ||
} | ||
|
||
s = s.toLowerCase(); | ||
if (hasProperty(optionNameMap, s)) { | ||
const opt = optionNameMap[s]; | ||
|
||
|
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.
This no longer works correctly because
shortOptionNames
uses lowercase keysThere 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.
Example:
tsc -V
will throw an errorGot it.