Skip to content

Commit

Permalink
fix(@angular/cli): show blueprints in completion script
Browse files Browse the repository at this point in the history
Close #4571
  • Loading branch information
catull authored and filipesilva committed Feb 14, 2017
1 parent e55cb82 commit 26b1ee4
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 26 deletions.
37 changes: 26 additions & 11 deletions packages/@angular/cli/commands/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ 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 {
const output: String[] = [];
function extractOptions(opts: any): string {
const output: string[] = [];

for (let index = 0; index < opts.length; index++) {
const element = opts[index];
Expand All @@ -21,20 +21,30 @@ function extractOptions(opts: any): String {
return output.sort().join(' ');
}

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(' ');
}

export interface CompletionCommandOptions {
all?: boolean;
bash?: boolean;
zsh?: boolean;
};

const commandsToIgnore = [
'easter-egg',
'init',
'destroy',
'github-pages-deploy' // errors because there is no base github-pages command
'easter-egg',
'init'
];

const optsNg: String[] = [];
const optsNg: string[] = [];

const CompletionCommand = Command.extend({
name: 'completion',
Expand Down Expand Up @@ -70,7 +80,7 @@ const CompletionCommand = Command.extend({

commandFiles.forEach(cmd => {
const Command = lookupCommand(commandMap, cmd);
const com: String[] = [];
const com: string[] = [];

const command = new Command({
ui: this.ui,
Expand All @@ -83,21 +93,26 @@ const CompletionCommand = Command.extend({
com.push(command.name);

if (command.aliases) {
command.aliases.forEach((element: String) => {
command.aliases.forEach((element: string) => {
optsNg.push(element);
com.push(element);
});
}

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

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

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

console.log(stripIndent`
###-begin-ng-completion###
Expand Down
26 changes: 11 additions & 15 deletions packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ const EmberGenerateCommand = require('../ember-cli/lib/commands/generate');
const Blueprint = require('../ember-cli/lib/models/blueprint');
const SilentError = require('silent-error');

const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
const blueprints = blueprintList
.filter(bp => bp.indexOf('-test') === -1)
.filter(bp => bp !== 'ng2')
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));

const GenerateCommand = EmberGenerateCommand.extend({
name: 'generate',

beforeRun: function(rawArgs: string[]) {
blueprints: blueprints,

beforeRun: function (rawArgs: string[]) {
if (!rawArgs.length) {
return;
}
Expand All @@ -22,7 +29,7 @@ const GenerateCommand = EmberGenerateCommand.extend({
if (rawArgs[0] !== '--help' &&
!fs.existsSync(path.join(__dirname, '..', 'blueprints', rawArgs[0]))) {
SilentError.debugOrThrow('@angular/cli/commands/generate',
`Invalid blueprint: ${rawArgs[0]}`);
`Invalid blueprint: ${rawArgs[0]}`);
}

if (!rawArgs[1]) {
Expand All @@ -31,20 +38,9 @@ const GenerateCommand = EmberGenerateCommand.extend({
}

// Override default help to hide ember blueprints
EmberGenerateCommand.prototype.printDetailedHelp = function() {
const blueprintList = fs.readdirSync(path.join(__dirname, '..', 'blueprints'));
const blueprints = blueprintList
.filter(bp => bp.indexOf('-test') === -1)
.filter(bp => bp !== 'ng2')
.map(bp => Blueprint.load(path.join(__dirname, '..', 'blueprints', bp)));

let output = '';
blueprints
.forEach(function (bp) {
output += bp.printBasicHelp(false) + os.EOL;
});
EmberGenerateCommand.prototype.printDetailedHelp = function () {
this.ui.writeLine(chalk.cyan(' Available blueprints'));
this.ui.writeLine(output);
this.ui.writeLine(blueprints.map(bp => bp.printBasicHelp(false)).join(os.EOL));
};

return EmberGenerateCommand.prototype.beforeRun.apply(this, arguments);
Expand Down

0 comments on commit 26b1ee4

Please sign in to comment.