8000 Clean up usage of ts-command-line. · syengineering/rushstack@8cfd74b · GitHub
[go: up one dir, main page]

Skip to content

Commit 8cfd74b

Browse files
committed
Clean up usage of ts-command-line.
1 parent 0d8a168 commit 8cfd74b

File tree

55 files changed

+309
-386
lines changed

Some content is hidden

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

55 files changed

+309
-386
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ export class ApiDocumenterCommandLine extends CommandLineParser {
1717
this._populateActions();
1818
}
1919

20-
protected onDefineParameters(): void {
21-
// override
22-
// No parameters
23-
}
24-
2520
private _populateActions(): void {
2621
this.addAction(new MarkdownAction(this));
2722
this.addAction(new YamlAction(this));

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
33

44
import * as path from 'path';
55
import * as tsdoc from '@microsoft/tsdoc';
6-
import colors from 'colors';
6+
import colors from 'colors/safe';
77

8-
import { CommandLineAction, CommandLineStringParameter } from '@rushstack/ts-command-line';
8+
import {
9+
CommandLineAction,
10+
CommandLineStringParameter,
11+
type ICommandLineActionOptions
12+
} from '@rushstack/ts-command-line';
913
import { FileSystem } from '@rushstack/node-core-library';
1014
import {
1115
ApiModel,
@@ -22,10 +26,12 @@ export interface IBuildApiModelResult {
2226
}
2327

2428
export abstract class BaseAction extends CommandLineAction {
25-
private _inputFolderParameter!: CommandLineStringParameter;
26-
private _outputFolderParameter!: CommandLineStringParameter;
29+
private readonly _inputFolderParameter: CommandLineStringParameter;
30+
private readonly _outputFolderPa F987 rameter: CommandLineStringParameter;
31+
32+
protected constructor(options: ICommandLineActionOptions) {
33+
super(options);
2734

28-
protected onDefineParameters(): void {
2935
// override
3036
this._inputFolderParameter = this.defineStringParameter({
3137
parameterLongName: '--input-folder',

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import { YamlDocumenter } from '../documenters/YamlDocumenter';
1010
import { OfficeYamlDocumenter } from '../documenters/OfficeYamlDocumenter';
1111

1212
export class YamlAction extends BaseAction {
13-
private _officeParameter!: CommandLineFlagParameter;
14-
private _newDocfxNamespacesParameter!: CommandLineFlagParameter;
15-
private _yamlFormatParameter!: CommandLineChoiceParameter;
13+
private readonly _officeParameter: CommandLineFlagParameter;
14+
private readonly _newDocfxNamespacesParameter: CommandLineFlagParameter;
15+
private readonly _yamlFormatParameter: CommandLineChoiceParameter;
1616

1717
public constructor(parser: ApiDocumenterCommandLine) {
1818
super({
@@ -23,11 +23,6 @@ export class YamlAction extends BaseAction {
2323
' to the universal reference YAML format, which is used by the docs.microsoft.com' +
2424
' pipeline.'
2525
});
26-
}
27-
28-
protected onDefineParameters(): void {
29-
// override
30-
super.onDefineParameters();
3126

3227
this._officeParameter = this.defineFlagParameter({
3328
parameterLongName: '--office',

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { RunAction } from './RunAction';
1111
import { InitAction } from './InitAction';
1212

1313
export class ApiExtractorCommandLine extends CommandLineParser {
14-
private _debugParameter!: CommandLineFlagParameter;
14+
private readonly _debugParameter: CommandLineFlagParameter;
1515

1616
public constructor() {
1717
super({
@@ -24,10 +24,7 @@ export class ApiExtractorCommandLine extends CommandLineParser {
2424
' tool such as api-documenter. For details, please visit the web site.'
2525
});
2626
this._populateActions();
27-
}
2827

29-
protected onDefineParameters(): void {
30-
// override
3128
this._debugParameter = this.defineFlagParameter({
3229
parameterLongName: '--debug',
3330
parameterShortName: '-d',

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ export class InitAction extends CommandLineAction {
2121
});
2222
}
2323

24-
protected onDefineParameters(): void {
25-
// override
26-
// No parameters yet
27-
}
28-
2924
protected async onExecute(): Promise<void> {
3025
// override
3126
const inputFilePath: string = path.resolve(__dirname, '../schemas/api-extractor-template.json');

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

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,19 @@ import { ApiExtractorCommandLine } from './ApiExtractorCommandLine';
1818
import { ExtractorConfig, IExtractorConfigPrepareOptions } from '../api/ExtractorConfig';
1919

2020
export class RunAction extends CommandLineAction {
21-
private _configFileParameter!: CommandLineStringParameter;
22-
private _localParameter!: CommandLineFlagParameter;
23-
private _verboseParameter!: CommandLineFlagParameter;
24-
private _diagnosticsParameter!: CommandLineFlagParameter;
25-
private _typescriptCompilerFolder!: CommandLineStringParameter;
21+
private readonly _configFileParameter: CommandLineStringParameter;
22+
private readonly _localParameter: CommandLineFlagParameter;
23+
private readonly _verboseParameter: CommandLineFlagParameter;
24+
private readonly _diagnosticsParameter: CommandLineFlagParameter;
25+
private readonly _typescriptCompilerFolder: CommandLineStringParameter;
2626

2727
public constructor(parser: ApiExtractorCommandLine) {
2828
super({
2929
actionName: 'run',
3030
summary: 'Invoke API Extractor on a project',
3131
documentation: 'Invoke API Extractor on a project'
3232
});
33-
}
3433

35-
protected onDefineParameters(): void {
36-
// override
3734
this._configFileParameter = this.defineStringParameter({
3835
parameterLongName: '--config',
3936
parameterShortName: '-c',

apps/heft/src/cli/HeftCommandLineParser.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ export class HeftCommandLineParser extends CommandLineParser {
5757

5858
private _preInitializationArgumentValues: IPreInitializationArgumentValues;
5959

60-
private _unmanagedFlag!: CommandLineFlagParameter;
61-
private _debugFlag!: CommandLineFlagParameter;
62-
private _pluginsParameter!: CommandLineStringListParameter;
60+
private readonly _unmanagedFlag: CommandLineFlagParameter;
61+
private readonly _debugFlag: CommandLineFlagParameter;
62+
private readonly _pluginsParameter: CommandLineStringListParameter;
6363

6464
public get isDebug(): boolean {
6565
return !!this._preInitializationArgumentValues.debug;
@@ -75,6 +75,26 @@ export class HeftCommandLineParser extends CommandLineParser {
7575
toolDescription: 'Heft is a pluggable build system designed for web projects.'
7676
});
7777

78+
this._unmanagedFlag = this.defineFlagParameter({
79+
parameterLongName: '--unmanaged',
80+
description:
81+
'Disables the Heft version selector: When Heft is invoked via the shell path, normally it' +
82+
" will examine the project's package.json dependencies and try to use the locally installed version" +
83+
' of Heft. Specify "--unmanaged" to force the invoked version of Heft to be used. This is useful for' +
84+
' example if you want to test a different version of Heft.'
85+
});
86+
87+
this._debugFlag = this.defineFlagParameter({
88+
parameterLongName: Constants.debugParameterLongName,
89+
description: 'Show the full call stack if an error occurs while executing the tool'
90+
});
91+
92+
this._pluginsParameter = this.defineStringListParameter({
93+
parameterLongName: Constants.pluginParameterLongName,
94+
argumentName: 'PATH',
95+
description: 'Used to specify Heft plugins.'
96+
});
97+
7898
this._preInitializationArgumentValues = this._getPreInitializationArgumentValues();
7999

80100
this._terminalProvider = new ConsoleTerminalProvider();
@@ -139,28 +159,6 @@ export class HeftCommandLineParser extends CommandLineParser {
139159
this.addAction(testAction);
140160
}
141161

142-
protected onDefineParameters(): void {
143-
this._unmanagedFlag = this.defineFlagParameter({
144-
parameterLongName: '--unmanaged',
145-
description:
146-
'Disables the Heft version selector: When Heft is invoked via the shell path, normally it' +
147-
" will examine the project's package.json dependencies and try to use the locally installed version" +
148-
' of Heft. Specify "--unmanaged" to force the invoked version of Heft to be used. This is useful for' +
149-
' example if you want to test a different version of Heft.'
150-
});
151-
152-
this._debugFlag = this.defineFlagParameter({
153-
parameterLongName: Constants.debugParameterLongName,
154-
description: 'Show the full call stack if an error occurs while executing the tool'
155-
});
156-
157-
this._pluginsParameter = this.defineStringListParameter({
158-
parameterLongName: Constants.pluginParameterLongName,
159-
argumentName: 'PATH',
160-
description: 'Used to specify Heft plugins.'
161-
});
162-
}
163-
164162
public async execute(args?: string[]): Promise<boolean> {
165163
// Defensively set the exit code to 1 so if the tool crashes for whatever reason, we'll have a nonzero exit code.
166164
process.exitCode = 1;

apps/heft/src/cli/actions/BuildAction.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import { Logging } from '../../utilities/Logging';
99
import { BuildStage, IBuildStageOptions, IBuildStageStandardParameters } from '../../stages/BuildStage';
1010

1111
export class BuildAction extends HeftActionBase {
12-
protected _watchFlag!: CommandLineFlagParameter;
13-
protected _productionFlag!: CommandLineFlagParameter;
14-
protected _liteFlag!: CommandLineFlagParameter;
15-
private _buildStandardParameters!: IBuildStageStandardParameters;
16-
private _cleanFlag!: CommandLineFlagParameter;
12+
protected readonly _watchFlag: CommandLineFlagParameter;
13+
protected readonly _productionFlag: CommandLineFlagParameter;
14+
protected readonly _liteFlag: CommandLineFlagParameter;
15+
private readonly _buildStandardParameters: IBuildStageStandardParameters;
16+
private readonly _cleanFlag: CommandLineFlagParameter;
1717

1818
public constructor(
1919
heftActionOptions: IHeftActionBaseOptions,
@@ -24,10 +24,6 @@ export class BuildAction extends HeftActionBase {
2424
}
2525
) {
2626
super(commandLineActionOptions, heftActionOptions);
27-
}
28-
29-
public onDefineParameters(): void {
30-
super.onDefineParameters();
3127

3228
this._buildStandardParameters = BuildStage.defineStageStandardParameters(this);
3329
this._productionFlag = this._buildStandardParameters.productionFlag;

apps/heft/src/cli/actions/CleanAction.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { HeftActionBase, IHeftActionBaseOptions } from './HeftActionBase';
77
import { CleanStage, ICleanStageOptions } from '../../stages/CleanStage';
88

99
export class CleanAction extends HeftActionBase {
10-
private _deleteCacheFlag!: CommandLineFlagParameter;
10+
private readonly _deleteCacheFlag: CommandLineFlagParameter;
1111

1212
public constructor(options: IHeftActionBaseOptions) {
1313
super(
@@ -18,10 +18,6 @@ export class CleanAction extends HeftActionBase {
1818
},
1919
options
2020
);
21-
}
22-
23-
public onDefineParameters(): void {
24-
super.onDefineParameters();
2521

2622
this._deleteCacheFlag = this.defineFlagParameter({
2723
parameterLongName: '--clear-cache',

apps/heft/src/cli/actions/CustomAction.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ export interface ICustomActionOptions<TParameters> {
6565
}
6666

6767
export class CustomAction<TParameters> extends HeftActionBase {
68-
private _customActionOptions: ICustomActionOptions<TParameters>;
69-
private _parameterValues!: Map<string, () => CustomActionParameterType>;
68+
private readonly _customActionOptions: ICustomActionOptions<TParameters>;
69+
private readonly _parameterValues: Map<string, () => CustomActionParameterType>;
7070

7171
public constructor(
7272
customActionOptions: ICustomActionOptions<TParameters>,
@@ -82,10 +82,6 @@ export class CustomAction<TParameters> extends HeftActionBase {
8282
);
8383

8484
this._customActionOptions = customActionOptions;
85-
}
86-
87-
public onDefineParameters(): void {
88-
super.onDefineParameters();
8985

9086
this._parameterValues = new Map<string, () => CustomActionParameterType>();
9187
for (const [callbackValueName, untypedParameterOption] of Object.entries(

0 commit comments

Comments
 (0)
0