Skip to content

Commit b7bbfab

Browse files
committed
Allow colons in command line action names
1 parent 7d5fe37 commit b7bbfab

File tree

6 files changed

+21
-21
lines changed

6 files changed

+21
-21
lines changed

apps/rush-lib/assets/rush-init/common/config/rush/command-line.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
/**
2727
* (Required) The name that will be typed as part of the command line. This is also the name
2828
* of the "scripts" hook in the project's package.json file.
29-
* The name should be comprised of lower case words separated by hyphens.
29+
* The name should be comprised of lower case words separated by hyphens or colons.
3030
*/
3131
"name": "my-bulk-command",
3232

libraries/ts-command-line/src/CommandLineAction.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export interface ICommandLineActionOptions {
3737
*/
3838
export abstract class CommandLineAction extends CommandLineParameterProvider {
3939
// Example: "do-something"
40-
private static _actionNameRegExp: RegExp = /^[a-z]+(-[a-z]+)*$/;
40+
private static _actionNameRegExp: RegExp = /^[a-z]+([-:][a-z]+)*$/;
4141

4242
/** {@inheritDoc ICommandLineActionOptions.actionName} */
4343
public readonly actionName: string;
@@ -55,7 +55,7 @@ export abstract class CommandLineAction extends CommandLineParameterProvider {
5555

5656
if (!CommandLineAction._actionNameRegExp.test(options.actionName)) {
5757
throw new Error(`Invalid action name "${options.actionName}". `
58-
+ `The name must be comprised of lower-case words optionally separated by hyphens.`);
58+
+ `The name must be comprised of lower-case words optionally separated by hyphens or colons.`);
5959
}
6060

6161
this.actionName = options.actionName;

libraries/ts-command-line/src/test/CommandLineParameter.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function createParser(): DynamicCommandLineParser {
2222
});
2323

2424
const action: DynamicCommandLineAction = new DynamicCommandLineAction({
25-
actionName: 'do-job',
25+
actionName: 'do:the-job',
2626
summary: 'does the job',
2727
documentation: 'a longer description'
2828
});
@@ -133,17 +133,17 @@ describe('CommandLineParameter', () => {
133133

134134
it('prints the action help', () => {
135135
const commandLineParser: CommandLineParser = createParser();
136-
const helpText: string = colors.stripColors(commandLineParser.getAction('do-job').renderHelpText());
136+
const helpText: string = colors.stripColors(commandLineParser.getAction('do:the-job').renderHelpText());
137137
expect(helpText).toMatchSnapshot();
138138
});
139139

140140
it('parses an input with ALL parameters', () => {
141141
const commandLineParser: CommandLineParser = createParser();
142-
const action: CommandLineAction = commandLineParser.getAction('do-job');
142+
const action: CommandLineAction = commandLineParser.getAction('do:the-job');
143143

144144
const args: string[] = [
145145
'--global-flag',
146-
'do-job',
146+
'do:the-job',
147147
'--choice', 'two',
148148
'--flag',
149149
'--integer', '123',
@@ -209,8 +209,8 @@ describe('CommandLineParameter', () => {
209209

210210
it('parses an input with NO parameters', () => {
211211
const commandLineParser: CommandLineParser = createParser();
212-
const action: CommandLineAction = commandLineParser.getAction('do-job');
213-
const args: string[] = [ 'do-job', '--integer-required', '123'];
212+
const action: CommandLineAction = commandLineParser.getAction('do:the-job');
213+
const args: string[] = [ 'do:the-job', '--integer-required', '123'];
214214

215215
return commandLineParser.execute(args).then(() => {
216216
expect(commandLineParser.selectedAction).toBe(action);

libraries/ts-command-line/src/test/CommandLineParser.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestAction extends CommandLineAction {
1111

1212
public constructor() {
1313
super({
14-
actionName: 'do-job',
14+
actionName: 'do:the-job',
1515
summary: 'does the job',
1616
documentation: 'a longer description'
1717
});
@@ -51,9 +51,9 @@ describe('CommandLineParser', () => {
5151
it('executes an action', () => {
5252
const commandLineParser: TestCommandLine = new TestCommandLine();
5353

54-
return commandLineParser.execute(['do-job', '--flag']).then(() => {
54+
return commandLineParser.execute(['do:the-job', '--flag']).then(() => {
5555
expect(commandLineParser.selectedAction).toBeDefined();
56-
expect(commandLineParser.selectedAction!.actionName).toEqual('do-job');
56+
expect(commandLineParser.selectedAction!.actionName).toEqual('do:the-job');
5757

5858
const action: TestAction = commandLineParser.selectedAction as TestAction;
5959
expect(action.done).toBe(true);

libraries/ts-command-line/src/test/DynamicCommandLineParser.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('DynamicCommandLineParser', () => {
1616
);
1717

1818
const action: DynamicCommandLineAction = new DynamicCommandLineAction({
19-
actionName: 'do-job',
19+
actionName: 'do:the-job',
2020
summary: 'does the job',
2121
documentation: 'a longer description'
2222
});
@@ -26,7 +26,7 @@ describe('DynamicCommandLineParser', () => {
2626
description: 'The flag'
2727
});
2828

29-
return commandLineParser.execute(['do-job', '--flag']).then(() => {
29+
return commandLineParser.execute(['do:the-job', '--flag']).then(() => {
3030
expect(commandLineParser.selectedAction).toEqual(action);
3131

3232
const retrievedParameter: CommandLineFlagParameter = action.getFlagParameter('--flag');

libraries/ts-command-line/src/test/__snapshots__/CommandLineParameter.test.ts.snap

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,12 @@ Array [
359359
`;
360360

361361
exports[`CommandLineParameter prints the action help 1`] = `
362-
"usage: example do-job [-h] [-c {one,two,three,default}]
363-
[--choice-with-default {one,two,three,default}] [-f]
364-
[-i NUMBER] [--integer-with-default NUMBER]
365-
--integer-required NUMBER [-s TEXT]
366-
[--string-with-default TEXT] [-l LIST]
367-
362+
"usage: example do:the-job [-h] [-c {one,two,three,default}]
363+
[--choice-with-default {one,two,three,default}] [-f]
364+
[-i NUMBER] [--integer-with-default NUMBER]
365+
--integer-required NUMBER [-s TEXT]
366+
[--string-with-default TEXT] [-l LIST]
367+
368368
369369
a longer description
370370
@@ -408,7 +408,7 @@ An example project
408408
409409
Positional arguments:
410410
<command>
411-
do-job does the job
411+
do:the-job does the job
412412
413413
Optional arguments:
414414
-h, --help Show this help message and exit.

0 commit comments

Comments
 (0)