Skip to content

Commit

Permalink
fix(@angular/cli): correctly build completion with blueprints and opt…
Browse files Browse the repository at this point in the history
…ions

before, if both blueprints and options are present, a space was missing between
them, resulting in "service--dryrun" instead of "service --dryrun"

Patch v2:
* use template string
* fix indentation of generated bash output
  • Loading branch information
georgmu authored and filipesilva committed Mar 29, 2017
1 parent c9d8243 commit dfe5990
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions packages/@angular/cli/commands/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const stringUtils = require('ember-cli-string-utils');
const Command = require('../ember-cli/lib/models/command');
const lookupCommand = require('../ember-cli/lib/cli/lookup-command');

function extractOptions(opts: any): string {
function extractOptions(opts: any): string[] {
const output: string[] = [];

for (let index = 0; index < opts.length; index++) {
Expand All @@ -18,18 +18,18 @@ function extractOptions(opts: any): string {
}
}

return output.sort().join(' ');
return output;
}

function extractBlueprints(opts: any): string {
function extractBlueprints(opts: any): string[] {
const output: string[] = [];

for (let index = 0; index < opts.length; index++) {
const element = opts[index];
output.push(element.name);
}

return output.sort().join(' ');
return output;
}

export interface CompletionCommandOptions {
Expand Down Expand Up @@ -117,20 +117,21 @@ const CompletionCommand = Command.extend({
});
}

let opts = '';
let opts: string[] = [];
if (command.blueprints && command.blueprints[0]) {
opts += extractBlueprints(command.blueprints);
opts = opts.concat(extractBlueprints(command.blueprints));
}

if (command.availableOptions && command.availableOptions[0]) {
opts += extractOptions(command.availableOptions);
caseBlock = caseBlock + ' ' + com.sort().join('|') + ') opts="' + opts + '" ;;\n';
opts = opts.concat(extractOptions(command.availableOptions));
const optsStr = opts.sort().join(' ');
caseBlock = `${caseBlock}
${com.sort().join('|')}) opts="${optsStr}" ;;`;
}
});

caseBlock = 'ng|help) opts="' + optsNg.sort().join(' ') + '" ;;\n' +
caseBlock +
' *) opts="" ;;';
caseBlock = `ng|help) opts="${optsNg.sort().join(' ')}" ;;${caseBlock}
*) opts="" ;;`;

console.log(stripIndent`
###-begin-ng-completion###
Expand Down

0 comments on commit dfe5990

Please sign in to comment.