Skip to content

Commit cb453f5

Browse files
voxsimarcanis
authored andcommitted
Ensure that every command has setFlags and hasWrapper functions (#3105)
* ensure that every command has setFlags function * ensure that every command has hasWrapper function
1 parent ab97b0f commit cb453f5

34 files changed

+130
-29
lines changed

src/cli/commands/_build-sub-commands.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ type SubCommands = {
1313
type Return = {
1414
run: CLIFunction,
1515
setFlags: (commander: Object) => void,
16+
hasWrapper: (commander: Object, Array<string>) => boolean,
1617
examples: Array<string>,
1718
};
1819

@@ -49,9 +50,13 @@ export default function(rootCommandName: string, subCommands: SubCommands, usage
4950
return Promise.reject(new MessageError(reporter.lang('invalidCommand', subCommandNames.join(', '))));
5051
}
5152

53+
function hasWrapper(): boolean {
54+
return true;
55+
}
56+
5257
const examples = usage.map((cmd: string): string => {
5358
return `${rootCommandName} ${cmd}`;
5459
});
5560

56-
return {run, setFlags, examples};
61+
return {run, setFlags, hasWrapper, examples};
5762
}

src/cli/commands/_useless.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,7 @@ export default function(message: string): { run: Function, useless: boolean } {
88
run() {
99
throw new MessageError(message);
1010
},
11+
setFlags: () => {},
12+
hasWrapper: () => true,
1113
};
1214
}

src/cli/commands/access.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import buildSubCommands from './_build-sub-commands.js';
44

5-
export const {run, setFlags} = buildSubCommands('access', {
5+
export const {run, setFlags, hasWrapper, examples} = buildSubCommands('access', {
66
public(): Promise<void> {
77
return Promise.reject(new Error('TODO'));
88
},

src/cli/commands/add.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ export class Add extends Install {
181181
}
182182
}
183183

184+
export function hasWrapper(): boolean {
185+
return true;
186+
}
187+
184188
export function setFlags(commander: Object) {
185189
commander.usage('add [packages ...] [flags]');
186190
commander.option('-D, --dev', 'save package to your `devDependencies`');

src/cli/commands/bin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import RegistryYarn from '../../resolvers/registries/yarn-resolver.js';
66

77
const path = require('path');
88

9-
export function hasWrapper() {}
9+
export function hasWrapper(): boolean {
10+
return false;
11+
}
12+
13+
export function setFlags() {}
1014

1115
export function run(
1216
config: Config,

src/cli/commands/cache.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function hasWrapper(flags: Object, args: Array<string>): boolean {
1212
return args[0] !== 'dir';
1313
}
1414

15-
export const {run, setFlags} = buildSubCommands('cache', {
15+
export const {run, setFlags, examples} = buildSubCommands('cache', {
1616
async ls(
1717
config: Config,
1818
reporter: Reporter,

src/cli/commands/check.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ const path = require('path');
1414
export const requireLockfile = false;
1515
export const noArguments = true;
1616

17+
export function hasWrapper(): boolean {
18+
return true;
19+
}
20+
1721
export function setFlags(commander: Object) {
1822
commander.option('--integrity');
1923
commander.option('--verify-tree');

src/cli/commands/clean.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,5 @@ export async function run(
127127
reporter.info(reporter.lang('cleanRemovedFiles', removedFiles));
128128
reporter.info(reporter.lang('cleanSavedSize', Number((removedSize / 1024 / 1024).toFixed(2))));
129129
}
130+
131+
export function setFlags() {}

src/cli/commands/config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export function hasWrapper(flags: Object, args: Array<string>): boolean {
99
return args[0] !== 'get';
1010
}
1111

12-
export const {run, setFlags} = buildSubCommands('config', {
12+
export const {run, setFlags, examples} = buildSubCommands('config', {
1313
async set(
1414
config: Config,
1515
reporter: Reporter,

src/cli/commands/help.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export function hasWrapper(): boolean {
1111
return false;
1212
}
1313

14+
export function setFlags() {}
15+
1416
export function run(
1517
config: Config,
1618
reporter: Reporter,
@@ -27,10 +29,7 @@ export function run(
2729
const command = commands[commandName];
2830

2931
if (command) {
30-
if (typeof command.setFlags === 'function') {
31-
command.setFlags(commander);
32-
}
33-
32+
command.setFlags(commander);
3433
const examples: Array<string> = (command && command.examples) || [];
3534
if (examples.length) {
3635
commander.on('--help', () => {

0 commit comments

Comments
 (0)