-
Notifications
You must be signed in to change notification settings - Fork 604
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
[ts-command-line] Add defineCommandLineRemainder() feature #1869
Conversation
…eter - Provide a way for an CommandLineStringListParameter environmentVariable to specify multiple values using a JSON array
- Fix a bug where CommandLineParser could not be declared without actions - Prohibit defineCommandLineRemainder() on the parser if it has actions
// with escaping here seems unwise, since there are so many shell escaping mechanisms that could | ||
// potentially confuse the experience. | ||
this._values = [ environmentValue ]; | ||
if (environmentValue[0] === '[') { |
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.
Can environmentVariableValue
be an empty string ""
?
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.
In Bash, it is easy to assign an empty string to an environment variable:
export MY_VARIABLE=
For the DOS cmd.exe shell, it is possible for the value to be an empty string, but you cannot use SET to assign it -- doing so will delete the variable. So it has to be assigned using some other tool. PowerShell can probably do it.
If you're asking about the design here, because an empty string does not start with [
, it will simply become the first item in the list.
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 was asking because if environmentValue
can be ""
then accessing environmentValue[0]
can throw whenever the string is empty but not undefined. The string can become ""
if it was originally whitespace entirely and then we trimmed the string.
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.
Yes in C#, not true in JavaScript.
// with escaping here seems unwise, since there are so many shell escaping mechanisms that could | ||
// potentially confuse the experience. | ||
this._values = [ environmentValue ]; | ||
if (environmentValue[0] === '[') { |
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.
Can environmentVariableValue
start with whitespace characters?
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.
Yes, but then it will not be parsed as an array. The entire string will simply become the first item in the list.
Hmm... that might be counterintuitive if a person is typing the value into a text box in a web page (e.g. AzureDev Ops). I'll trim it. 👍
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 also documented the parsing rules.
@@ -0,0 +1,20 @@ | |||
const fsx = require('fs-extra'); |
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.
Why not FileSystem
?
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 library predates node-core-library
. If we ever do an operation that would genuinely benefit, I'll add it as a dependency.
}, | ||
"include": [ | ||
"src/**/*.ts", | ||
"typings/tsd.d.ts" |
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.
Remove?
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 project doesn't use RSC because it's intended as a code sample.
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 right, but tsd.d.ts
isn't needed; removed.
if (!this.selectedAction) { | ||
return Promise.resolve(); | ||
} | ||
return this.selectedAction._execute(); |
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.
Why not turn this into an async
function and:
if (!this.selectedAction) { | |
return Promise.resolve(); | |
} | |
return this.selectedAction._execute(); | |
if (this.selectedAction) { | |
await this.selectedAction._execute(); | |
} |
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'm going to bulk-convert everything to async
/await
, but not in this PR. It needs to be a standalone PR.
|
||
return commandLineParser.execute(['--flag', 'the', 'remaining', 'args']).then(() => { | ||
expect(commandLineParser.selectedAction).toBeUndefined(); | ||
// expect(commandLineParser.flag.value).toBe(true); |
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.
Remove?
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.
Oops, that was not meant to be disabled. I've uncommented it.
4d07147
to
bcc3be1
Compare
This was published as ts-command-line version 4.4.0. |
This PR adds a new feature to
ts-command-line
that enables the remaining CLI arguments to be captured, without any validation. We want this for #1232 (comment) so thatrushx
can pass its arguments along to another command.While I was in there, I fixed a bunch of other minor issues with
ts-command-line
:I also added a ts-command-line-test project that makes it easier to debug the library.