Skip to content
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

Ensure that every command has setFlags and hasWrapper functions #3105

Merged
merged 2 commits into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/cli/commands/_build-sub-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type SubCommands = {
type Return = {
run: CLIFunction,
setFlags: (commander: Object) => void,
hasWrapper: (commander: Object, Array<string>) => boolean,
examples: Array<string>,
};

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

function hasWrapper(): boolean {
return true;
}

const examples = usage.map((cmd: string): string => {
return `${rootCommandName} ${cmd}`;
});

return {run, setFlags, examples};
return {run, setFlags, hasWrapper, examples};
}
2 changes: 2 additions & 0 deletions src/cli/commands/_useless.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,7 @@ export default function(message: string): { run: Function, useless: boolean } {
run() {
throw new MessageError(message);
},
setFlags: () => {},
hasWrapper: () => true,
};
}
2 changes: 1 addition & 1 deletion src/cli/commands/access.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

export const {run, setFlags} = buildSubCommands('access', {
export const {run, setFlags, hasWrapper, examples} = buildSubCommands('access', {
public(): Promise<void> {
return Promise.reject(new Error('TODO'));
},
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export class Add extends Install {
}
}

export function hasWrapper(): boolean {
return true;
}

export function setFlags(commander: Object) {
commander.usage('add [packages ...] [flags]');
commander.option('-D, --dev', 'save package to your `devDependencies`');
Expand Down
6 changes: 5 additions & 1 deletion src/cli/commands/bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import RegistryYarn from '../../resolvers/registries/yarn-resolver.js';

const path = require('path');

export function hasWrapper() {}
export function hasWrapper(): boolean {
return false;
}

export function setFlags() {}

export function run(
config: Config,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function hasWrapper(flags: Object, args: Array<string>): boolean {
return args[0] !== 'dir';
}

export const {run, setFlags} = buildSubCommands('cache', {
export const {run, setFlags, examples} = buildSubCommands('cache', {
async ls(
config: Config,
reporter: Reporter,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/check.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ const path = require('path');
export const requireLockfile = false;
export const noArguments = true;

export function hasWrapper(): boolean {
return true;
}

export function setFlags(commander: Object) {
commander.option('--integrity');
commander.option('--verify-tree');
Expand Down
2 changes: 2 additions & 0 deletions src/cli/commands/clean.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ export async function run(
reporter.info(reporter.lang('cleanRemovedFiles', removedFiles));
reporter.info(reporter.lang('cleanSavedSize', Number((removedSize / 1024 / 1024).toFixed(2))));
}

export function setFlags() {}
2 changes: 1 addition & 1 deletion src/cli/commands/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function hasWrapper(flags: Object, args: Array<string>): boolean {
return args[0] !== 'get';
}

export const {run, setFlags} = buildSubCommands('config', {
export const {run, setFlags, examples} = buildSubCommands('config', {
async set(
config: Config,
reporter: Reporter,
Expand Down
7 changes: 3 additions & 4 deletions src/cli/commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ export function hasWrapper(): boolean {
return false;
}

export function setFlags() {}

export function run(
config: Config,
reporter: Reporter,
Expand All @@ -27,10 +29,7 @@ export function run(
const command = commands[commandName];

if (command) {
if (typeof command.setFlags === 'function') {
command.setFlags(commander);
}

command.setFlags(commander);
const examples: Array<string> = (command && command.examples) || [];
if (examples.length) {
commander.on('--help', () => {
Expand Down
6 changes: 6 additions & 0 deletions src/cli/commands/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,12 @@ export class Import extends Install {
}
}

export function setFlags() {}

export function hasWrapper(): boolean {
return true;
}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
6 changes: 6 additions & 0 deletions src/cli/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ function clean(object: any): any {
}
}

export function setFlags() {}

export function hasWrapper(): boolean {
return true;
}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export function setFlags(commander: Object) {
commander.option('-y, --yes', 'use default options');
}

export function hasWrapper(): boolean {
return true;
}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@ export class Install {
maybeOutputUpdate: any;
}

export function hasWrapper(): boolean {
return true;
}

export function setFlags(commander: Object) {
commander.usage('install [flags]');
commander.option('-g, --global', 'DEPRECATED');
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/licenses.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ async function getManifests(config: Config, flags: Object): Promise<Array<Manife
return manifests;
}

export const {run, setFlags} = buildSubCommands('licenses', {
export const {run, setFlags, examples} = buildSubCommands('licenses', {
async ls(
config: Config,
reporter: Reporter,
Expand Down
6 changes: 6 additions & 0 deletions src/cli/commands/link.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ export async function getRegistryFolder(config: Config, name: string): Promise<s
return path.join(config.cwd, registryFolder);
}

export function hasWrapper(): boolean {
return true;
}

export function setFlags() {}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ export function getParent(key: string, treesByKey: Object) : Object {
return treesByKey[parentKey];
}

export function hasWrapper(): boolean {
return true;
}

export function setFlags(commander: Object) {
commander.option('--depth [depth]', 'Limit the depth of the shown dependencies');
}
Expand Down
6 changes: 6 additions & 0 deletions src/cli/commands/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,12 @@ export async function getToken(config: Config, reporter: Reporter, name: string
}
}

export function hasWrapper(): boolean {
return true;
}

export function setFlags() {}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
6 changes: 6 additions & 0 deletions src/cli/commands/logout.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
import type {Reporter} from '../../reporters/index.js';
import type Config from '../../config.js';

export function setFlags() {}

export function hasWrapper(): boolean {
return true;
}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/outdated.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ export function setFlags(commander: Object) {
commander.usage('outdated [packages ...]');
}

export function hasWrapper(): boolean {
return true;
}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export async function mutate(
}
}

export const {run, setFlags} = buildSubCommands('owner', {
export const {run, setFlags, hasWrapper, examples} = buildSubCommands('owner', {
add(
config: Config,
reporter: Reporter,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ export function setFlags(commander: Object) {
commander.option('-f, --filename <filename>', 'filename');
}

export function hasWrapper(): boolean {
return true;
}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export function setFlags(commander: Object) {
commander.option('--tag [tag]', 'tag');
}

export function hasWrapper(): boolean {
return true;
}

async function publish(
config: Config,
pkg: any,
Expand Down
2 changes: 2 additions & 0 deletions src/cli/commands/remove.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const path = require('path');

export const requireLockfile = true;

export function setFlags() {}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
6 changes: 6 additions & 0 deletions src/cli/commands/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ function sanitizedArgs(args: Array<string>): Array<string> {
return newArgs;
}

export function setFlags() {}

export function hasWrapper(): boolean {
return true;
}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/tag.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export async function getName(args: Array<string>, config: Config): Promise<stri
}
}

export const {run, setFlags, examples} = buildSubCommands('tag', {
export const {run, setFlags, hasWrapper, examples} = buildSubCommands('tag', {
async add(
config: Config,
reporter: Reporter,
Expand Down
2 changes: 1 addition & 1 deletion src/cli/commands/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function wrapRequiredUser(callback: CLIFunctionWithParts): CLIFunction {
}, true);
}

export const {run, setFlags} = buildSubCommands('team', {
export const {run, setFlags, hasWrapper, examples} = buildSubCommands('team', {
create: wrapRequiredTeam(async function(
parts: TeamParts,
config: Config,
Expand Down
6 changes: 6 additions & 0 deletions src/cli/commands/unlink.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import {getBinFolder as getGlobalBinFolder} from './global';

const path = require('path');

export function setFlags() {}

export function hasWrapper(): boolean {
return true;
}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/upgrade-interactive.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ export function setFlags(commander: Object) {
commander.option('-T, --tilde', 'install most recent release with the same minor version');
}

export function hasWrapper(): boolean {
return true;
}

type InquirerResponses<K, T> = {[key: K]: Array<T>};

// Prompt user with Inquirer
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export function setFlags(commander: Object) {
commander.usage('upgrade [flags]');
}

export function hasWrapper(): boolean {
return true;
}

export const requireLockfile = true;

export async function run(
Expand Down
4 changes: 4 additions & 0 deletions src/cli/commands/version.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export function setFlags(commander: Object) {
commander.option('--no-git-tag-version', 'no git tag version');
}

export function hasWrapper(): boolean {
return true;
}

export async function setVersion(
config: Config,
reporter: Reporter,
Expand Down
6 changes: 6 additions & 0 deletions src/cli/commands/versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ import type Config from '../../config.js';

const YARN_VERSION = require('../../../package.json').version;

export function setFlags() {}

export function hasWrapper(): boolean {
return true;
}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
6 changes: 6 additions & 0 deletions src/cli/commands/why.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ function getSharedDependencies(
return sharedDependencies;
}

export function setFlags() {}

export function hasWrapper(): boolean {
return true;
}

export async function run(
config: Config,
reporter: Reporter,
Expand Down
Loading