diff --git a/packages/schematics/src/command-line/affected.ts b/packages/schematics/src/command-line/affected.ts index 7d219431f93123..a75891639f0c8f 100644 --- a/packages/schematics/src/command-line/affected.ts +++ b/packages/schematics/src/command-line/affected.ts @@ -11,6 +11,7 @@ export function affected(args: string[]): void { let apps: string[]; let projects: string[]; let rest: string[]; + try { const p = parseFiles(args.slice(1)); rest = p.rest; @@ -38,15 +39,6 @@ export function affected(args: string[]): void { } function printError(command: string, e: any) { - console.error( - `Pass the SHA range, as follows: npm run affected:${command} -- SHA1 SHA2.` - ); - console.error( - `Or pass the list of files, as follows: npm run affected:${command} -- --files="libs/mylib/index.ts,libs/mylib2/index.ts".` - ); - console.error( - `Or to get the list of files from local changes: npm run affected:${command} -- --uncommitted | --untracked.` - ); console.error(e.message); } diff --git a/packages/schematics/src/command-line/nx.ts b/packages/schematics/src/command-line/nx.ts index 3e826551371200..d32da7f73b538f 100644 --- a/packages/schematics/src/command-line/nx.ts +++ b/packages/schematics/src/command-line/nx.ts @@ -15,35 +15,52 @@ const args = process.argv.slice(3); yargs .usage('Usage: $0 [options>') .command( - 'affected ', + 'affected ', 'Compute affected applications', yargs => yargs - .positional('action', { - choices: ['apps', 'build', 'e2e', 'dep-graph'] + .option('files', { + type: 'array', + group: 'Compute apps affected by:', + describe: 'Specified files' + }) + .option('uncommitted', { + group: 'Compute apps affected by:', + describe: 'Uncommitted changes' + }) + .option('untracked', { + group: 'Compute apps affected by:', + describe: 'Untracked changes' + }) + .option('SHAs', { + type: 'array', + group: 'Compute apps affected by:', + describe: 'Files changed between two SHAs' }) - .command(' -- ', 'Targets within a range of SHAs') .command( - ' -- files=""', - 'Targets a comma delimited list of files' + 'apps', + 'Prints the names of the affected apps', + yargs => yargs, + () => affected(args) + ) + .command( + 'build', + 'Builds the affected apps', + yargs => yargs, + () => affected(args) + ) + .command( + 'e2e', + 'Tests the affected apps', + yargs => yargs, + () => affected(args) ) - .command(' -- --uncommitted', 'Targets uncommited changes') - .command(' -- --untracked', 'Targets untracked changes') - .demandCommand() .command( 'dep-graph', 'Generate a graph showing links between targets', yargs => yargs .describe('file', 'output file (e.g. --file=.vis/output.json)') - .command('-- ', 'Targets within a range of SHAs') - .command( - '-- files=""', - 'Targets a comma delimited list of files' - ) - .command('-- --uncommitted', 'Targets uncommited changes') - .command('-- --untracked', 'Targets untracked changes') - .demandCommand() .demand('file') .demand('output') .choices('output', [ @@ -55,17 +72,12 @@ yargs generateGraph(yargsParser(args)); } ) - .demandCommand() - .describe('args', 'Prints the names of the affected apps') - .describe('build', 'Builds the affected apps') - .describe('e2e', 'Tests the affected apps') - .describe( - 'dep-graph', - 'Generate a graph showing links between apps and libs' - ), - _ => { - affected(args); - } + .conflicts({ + files: ['uncommitted', 'untracked', 'SHAs'], + untracked: ['uncommitted', 'files', 'SHAs'], + SHAs: ['uncommitted', 'untracked', 'files'], + uncommitted: ['files', 'untracked', 'SHAs'] + }) ) .command( 'format ', @@ -81,11 +93,11 @@ yargs .command( // TODO: delete this after 1.0 'update ', - 'Migrate to the latest version of NX', + 'Update to the latest version of Nx', yargs => yargs - .describe('check', 'Check if there are migrations to run') - .describe('skip', 'Skip running the latest set of migrations'), + .describe('check', 'Check if there are Nx updates to run') + .describe('skip', 'Skip running the latest set of Nx updates'), _ => { update(args); } @@ -93,7 +105,7 @@ yargs .alias('update', 'migrates') // TODO: Remove after 1.0 .command( 'lint [files..]', - 'Line workspace or set of files', + 'Lint workspace or set of files', yargs => yargs, _ => { lint(); @@ -110,7 +122,7 @@ yargs ) .command( 'workspace-schematic ', - 'Generate a schematic `ng g `', + 'Generate a custom schematic that can be run via `ng g `', yargs => yargs.positional('name', { type: 'string', @@ -122,5 +134,5 @@ yargs ) .help('help') .version(false) - .strict() + .showHelpOnFail(true) .demandCommand().argv; // .argv bootstraps the CLI creation;