Skip to content

Commit f825a50

Browse files
authored
Merge pull request microsoft#611 from Microsoft/pgonzal/ts-command-line-dynamic
[ts-command-line] Add support for dynamic parsing (API change)
2 parents 4099529 + 8564b05 commit f825a50

48 files changed

Lines changed: 1688 additions & 320 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

apps/api-documenter/src/cli/BaseAction.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@ export abstract class BaseAction extends CommandLineAction {
2222
this._inputFolderParameter = this.defineStringParameter({
2323
parameterLongName: '--input-folder',
2424
parameterShortName: '-i',
25-
key: 'FOLDER1',
25+
argumentName: 'FOLDER1',
2626
description: `Specifies the input folder containing the *.api.json files to be processed.`
2727
+ ` If omitted, the default is "./input"`
2828
});
2929

3030
this._outputFolderParameter = this.defineStringParameter({
3131
parameterLongName: '--output-folder',
3232
parameterShortName: '-o',
33-
key: 'FOLDER2',
33+
argumentName: 'FOLDER2',
3434
description: `Specifies the output folder where the documentation will be written.`
3535
+ ` ANY EXISTING CONTENTS WILL BE DELETED!`
36-
+ ` If omitted, the default is "./${this.options.actionVerb}"`
36+
+ ` If omitted, the default is "./${this.actionName}"`
3737
});
3838
}
3939

@@ -45,7 +45,7 @@ export abstract class BaseAction extends CommandLineAction {
4545
throw new Error('The input folder does not exist: ' + this.inputFolder);
4646
}
4747

48-
this.outputFolder = this._outputFolderParameter.value || `./${this.options.actionVerb}`;
48+
this.outputFolder = this._outputFolderParameter.value || `./${this.actionName}`;
4949
if (!fsx.existsSync(this.outputFolder)) {
5050
throw new Error('The output folder does not exist: ' + this.outputFolder);
5151
}

apps/api-documenter/src/cli/MarkdownAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { MarkdownDocumenter } from '../markdown/MarkdownDocumenter';
99
export class MarkdownAction extends BaseAction {
1010
constructor(parser: ApiDocumenterCommandLine) {
1111
super({
12-
actionVerb: 'markdown',
12+
actionName: 'markdown',
1313
summary: 'Generate documentation as Markdown files (*.md)',
1414
documentation: 'Generates API documentation as a collection of files in'
1515
+ ' Markdown format, suitable for example for publishing on a GitHub site.'

apps/api-documenter/src/cli/YamlAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class YamlAction extends BaseAction {
1717

1818
constructor(parser: ApiDocumenterCommandLine) {
1919
super({
20-
actionVerb: 'yaml',
20+
actionName: 'yaml',
2121
summary: 'Generate documentation as universal reference YAML files (*.yml)',
2222
documentation: 'Generates API documentation as a collection of files conforming'
2323
+ ' to the universal reference YAML format, which is used by the docs.microsoft.com'

apps/api-extractor/src/cli/RunAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export class RunAction extends CommandLineAction {
2727

2828
constructor(parser: ApiExtractorCommandLine) {
2929
super({
30-
actionVerb: 'run',
30+
actionName: 'run',
3131
summary: 'Invoke API Extractor on a project',
3232
documentation: 'Invoke API Extractor on a project'
3333
});
@@ -38,7 +38,7 @@ export class RunAction extends CommandLineAction {
3838
this._configFileParameter = this.defineStringParameter({
3939
parameterLongName: '--config',
4040
parameterShortName: '-c',
41-
key: 'FILE',
41+
argumentName: 'FILE',
4242
description: `Use the specified ${AE_CONFIG_FILENAME} file path, rather than guessing its location`
4343
});
4444
this._localParameter = this.defineFlagParameter({

apps/rush-lib/src/cli/actions/BaseInstallAction.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export abstract class BaseInstallAction extends BaseRushAction {
1111
protected onDefineParameters(): void {
1212
this._authenticationTokensParameter = this.defineStringListParameter({
1313
parameterLongName: '--auth-token',
14+
argumentName: 'TOKEN',
1415
description: '(EXPERIMENTAL) List authentication tokens required to install packages. These must be in the '
1516
+ 'format of lines of a .npmrc file. They will be appended to the .npmrc file used during package installation.'
1617
});

apps/rush-lib/src/cli/actions/BaseRushAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ export abstract class BaseRushAction extends CommandLineAction {
6161
}
6262
}
6363

64-
console.log(`Starting "rush ${this.options.actionVerb}"${os.EOL}`);
64+
console.log(`Starting "rush ${this.actionName}"${os.EOL}`);
6565
return this.run();
6666
}
6767

apps/rush-lib/src/cli/actions/ChangeAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ export default class ChangeAction extends BaseRushAction {
7070
''
7171
];
7272
super({
73-
actionVerb: 'change',
73+
actionName: 'change',
7474
summary: 'Records changes made to projects, indicating how the package version number should be bumped ' +
7575
'for the next publish.',
7676
documentation: documentation.join(os.EOL),
@@ -88,7 +88,7 @@ export default class ChangeAction extends BaseRushAction {
8888
this._targetBranchParameter = this.defineStringParameter({
8989
parameterLongName: '--target-branch',
9090
parameterShortName: '-b',
91-
key: 'BRANCH',
91+
argumentName: 'BRANCH',
9292
description: 'If this parameter is specified, compare current branch with the target branch to get changes. ' +
9393
'If this parameter is not specified, the current branch is compared against the "master" branch.'
9494
});

apps/rush-lib/src/cli/actions/CheckAction.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { BaseRushAction } from './BaseRushAction';
1212
export default class CheckAction extends BaseRushAction {
1313
constructor(parser: RushCommandLineParser) {
1414
super({
15-
actionVerb: 'check',
15+
actionName: 'check',
1616
summary: 'Checks each project\'s package.json files and ensures that all dependencies are of the same ' +
1717
'version throughout the repository.',
1818
documentation: 'Checks each project\'s package.json files and ensures that all dependencies are of the ' +

apps/rush-lib/src/cli/actions/CustomCommandFactory.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,14 @@ export class CustomCommandFactory {
2727

2828
// always create a build and a rebuild command
2929
customActions.set('build', new CustomRushAction(parser, {
30-
actionVerb: 'build',
30+
actionName: 'build',
3131
summary: '(EXPERIMENTAL) Build all projects that haven\'t been built, or have changed since they were last '
3232
+ 'built.',
3333
documentation: documentationForBuild
3434
}, true));
3535

3636
customActions.set('rebuild', new CustomRushAction(parser, {
37-
actionVerb: 'rebuild',
37+
actionName: 'rebuild',
3838
summary: 'Clean and rebuild the entire set of projects',
3939
documentation: documentationForBuild
4040
}, true));
@@ -46,7 +46,7 @@ export class CustomCommandFactory {
4646
throw new Error(`Cannot define two custom actions with the same name: "${command.name}"`);
4747
}
4848
customActions.set(command.name, new CustomRushAction(parser, {
49-
actionVerb: command.name,
49+
actionName: command.name,
5050
summary: command.summary,
5151
documentation: command.documentation || command.summary
5252
},

apps/rush-lib/src/cli/actions/CustomRushAction.ts

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
CommandLineFlagParameter,
1919
CommandLineStringParameter,
2020
CommandLineStringListParameter,
21-
CommandLineOptionParameter,
21+
CommandLineChoiceParameter,
2222
ICommandLineActionOptions
2323
} from '@microsoft/ts-command-line';
2424

@@ -29,7 +29,7 @@ import { Stopwatch } from '../../utilities/Stopwatch';
2929

3030
interface ICustomOptionInstance {
3131
optionDefinition: CustomOption;
32-
parameterValue?: CommandLineFlagParameter | CommandLineOptionParameter;
32+
parameterValue?: CommandLineFlagParameter | CommandLineChoiceParameter;
3333
}
3434

3535
export class CustomRushAction extends BaseRushAction {
@@ -96,18 +96,18 @@ export class CustomRushAction extends BaseRushAction {
9696
}
9797
});
9898

99-
const changedProjectsOnly: boolean = this.options.actionVerb === 'build' && this._changedProjectsOnly.value;
99+
const changedProjectsOnly: boolean = this.actionName === 'build' && this._changedProjectsOnly.value;
100100

101101
const tasks: TaskSelector = new TaskSelector(
102102
{
103103
rushConfiguration: this.parser.rushConfiguration,
104-
toFlags: this._toFlag.value,
105-
fromFlags: this._fromFlag.value,
106-
commandToRun: this.options.actionVerb,
104+
toFlags: this._toFlag.values,
105+
fromFlags: this._fromFlag.values,
106+
commandToRun: this.actionName,
107107
customFlags,
108108
isQuietMode,
109109
parallelism,
110-
isIncrementalBuildAllowed: this.options.actionVerb === 'build',
110+
isIncrementalBuildAllowed: this.actionName === 'build',
111111
changedProjectsOnly,
112112
ignoreMissingScript: this._ignoreMissingScript
113113
}
@@ -116,12 +116,12 @@ export class CustomRushAction extends BaseRushAction {
116116
return tasks.execute().then(
117117
() => {
118118
stopwatch.stop();
119-
console.log(colors.green(`rush ${this.options.actionVerb} (${stopwatch.toString()})`));
119+
console.log(colors.green(`rush ${this.actionName} (${stopwatch.toString()})`));
120120
this._doAfterTask(stopwatch, true);
121121
},
122122
() => {
123123
stopwatch.stop();
124-
console.log(colors.red(`rush ${this.options.actionVerb} - Errors! (${stopwatch.toString()})`));
124+
console.log(colors.red(`rush ${this.actionName} - Errors! (${stopwatch.toString()})`));
125125
this._doAfterTask(stopwatch, false);
126126
this.parser.exitWithError();
127127
});
@@ -132,7 +132,7 @@ export class CustomRushAction extends BaseRushAction {
132132
this._parallelismParameter = this.defineStringParameter({
133133
parameterLongName: '--parallelism',
134134
parameterShortName: '-p',
135-
key: 'COUNT',
135+
argumentName: 'COUNT',
136136
description: 'Specify the number of concurrent build processes'
137137
+ ' The value "max" can be specified to indicate the number of CPU cores.'
138138
+ ' If this parameter omitted, the default value depends on the operating system and number of CPU cores.'
@@ -141,24 +141,24 @@ export class CustomRushAction extends BaseRushAction {
141141
this._toFlag = this.defineStringListParameter({
142142
parameterLongName: '--to',
143143
parameterShortName: '-t',
144-
key: 'PROJECT1',
144+
argumentName: 'PROJECT1',
145145
description: 'Run command in the specified project and all of its dependencies'
146146
});
147147
this._fromFlag = this.defineStringListParameter({
148148
parameterLongName: '--from',
149149
parameterShortName: '-f',
150-
key: 'PROJECT2',
150+
argumentName: 'PROJECT2',
151151
description: 'Run command in all projects that directly or indirectly depend on the specified project'
152152
});
153153
this._verboseParameter = this.defineFlagParameter({
154154
parameterLongName: '--verbose',
155155
parameterShortName: '-v',
156156
description: 'Display the logs during the build, rather than just displaying the build status summary'
157157
});
158-
if (this.options.actionVerb === 'build') {
158+
if (this.actionName === 'build') {
159159
this._changedProjectsOnly = this.defineFlagParameter({
160160
parameterLongName: '--changed-projects-only',
161-
parameterShortName: '-cpo',
161+
parameterShortName: '-o',
162162
description: 'If specified, the incremental build will only rebuild projects that have changed, '
163163
+ 'but not any projects that directly or indirectly depend on the changed package.'
164164
});
@@ -174,12 +174,12 @@ export class CustomRushAction extends BaseRushAction {
174174
description: customOption.optionDefinition.description
175175
});
176176
} else if (customOption.optionDefinition.optionType === 'enum') {
177-
customOption.parameterValue = this.defineOptionParameter({
177+
customOption.parameterValue = this.defineChoiceParameter({
178178
parameterShortName: customOption.optionDefinition.shortName,
179179
parameterLongName: longName,
180180
description: customOption.optionDefinition.description,
181181
defaultValue: customOption.optionDefinition.defaultValue,
182-
options: customOption.optionDefinition.enumValues.map((enumValue: ICustomEnumValue) => {
182+
alternatives: customOption.optionDefinition.enumValues.map((enumValue: ICustomEnumValue) => {
183183
return enumValue.name;
184184
})
185185
});
@@ -188,13 +188,13 @@ export class CustomRushAction extends BaseRushAction {
188188
}
189189

190190
private _isParallelized(): boolean {
191-
return this.options.actionVerb === 'build'
192-
|| this.options.actionVerb === 'rebuild'
191+
return this.actionName === 'build'
192+
|| this.actionName === 'rebuild'
193193
|| this._parallelized;
194194
}
195195

196196
private _doBeforeTask(): void {
197-
if (this.options.actionVerb !== 'build' && this.options.actionVerb !== 'rebuild') {
197+
if (this.actionName !== 'build' && this.actionName !== 'rebuild') {
198198
// Only collects information for built-in tasks like build or rebuild.
199199
return;
200200
}
@@ -203,7 +203,7 @@ export class CustomRushAction extends BaseRushAction {
203203
}
204204

205205
private _doAfterTask(stopwatch: Stopwatch, success: boolean): void {
206-
if (this.options.actionVerb !== 'build' && this.options.actionVerb !== 'rebuild') {
206+
if (this.actionName !== 'build' && this.actionName !== 'rebuild') {
207207
// Only collects information for built-in tasks like build or rebuild.
208208
return;
209209
}
@@ -214,20 +214,20 @@ export class CustomRushAction extends BaseRushAction {
214214

215215
private _collectTelemetry(stopwatch: Stopwatch, success: boolean): void {
216216
const extraData: { [key: string]: string } = {
217-
command_to: (!!this._toFlag.value).toString(),
218-
command_from: (!!this._fromFlag.value).toString()
217+
command_to: (!!this._toFlag.values).toString(),
218+
command_from: (!!this._fromFlag.values).toString()
219219
};
220220

221221
this.customOptions.forEach((customOption: ICustomOptionInstance, longName: string) => {
222222
if (customOption.parameterValue!.value) {
223-
extraData[`${this.options.actionVerb}_${longName}`] =
224-
customOption.parameterValue!.value.toString();
223+
extraData[`${this.actionName}_${longName}`] =
224+
customOption.parameterValue!.value!.toString();
225225
}
226226
});
227227

228228
if (this.parser.telemetry) {
229229
this.parser.telemetry.log({
230-
name: this.options.actionVerb,
230+
name: this.actionName,
231231
duration: stopwatch.duration,
232232
result: success ? 'Succeeded' : 'Failed',
233233
extraData

0 commit comments

Comments
 (0)