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

New help #8255

Merged
merged 3 commits into from
Nov 1, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 11 additions & 32 deletions packages/@angular/cli/commands/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { SchematicAvailableOptions } from '../tasks/schematic-get-options';
const Command = require('../ember-cli/lib/models/command');
const SilentError = require('silent-error');

const { cyan, grey, yellow } = chalk;
const { cyan, yellow } = chalk;
const separatorRegEx = /[\/\\]/g;


Expand Down Expand Up @@ -192,42 +192,21 @@ export default Command.extend({
const collection = getCollection(collectionName);
const schematicName = rawArgs[1];
if (schematicName) {
const SchematicGetOptionsTask = require('../tasks/schematic-get-options').default;
const getOptionsTask = new SchematicGetOptionsTask({
const SchematicGetHelpOutputTask = require('../tasks/schematic-get-help-output').default;
const getHelpOutputTask = new SchematicGetHelpOutputTask({
ui: this.ui,
project: this.project
});
return getOptionsTask.run({
return getHelpOutputTask.run({
schematicName,
collectionName
collectionName,
nonSchematicOptions: this.availableOptions.filter((o: any) => !o.hidden)
})
.then((availableOptions: SchematicAvailableOptions[]) => {
const output: string[] = [];
output.push(cyan(`ng generate ${schematicName} ${cyan('[name]')} ${cyan('<options...>')}`));
availableOptions
.filter(opt => opt.name !== 'name')
.forEach(opt => {
let text = cyan(` --${opt.name}`);
if (opt.schematicType) {
text += cyan(` (${opt.schematicType})`);
}
if (opt.schematicDefault) {
text += cyan(` (Default: ${opt.schematicDefault})`);
}
if (opt.description) {
text += ` ${opt.description}`;
}
output.push(text);
if (opt.aliases && opt.aliases.length > 0) {
const aliasText = opt.aliases.reduce(
(acc, curr) => {
return acc + ` -${curr}`;
},
'');
output.push(grey(` aliases: ${aliasText}`));
}
});
return output.join('\n');
.then((output: string[]) => {
return [
cyan(`ng generate ${schematicName} ${cyan('[name]')} ${cyan('<options...>')}`),
...output
].join('\n');
});
} else {
const schematicNames: string[] = engineHost.listSchematics(collection);
Expand Down
24 changes: 24 additions & 0 deletions packages/@angular/cli/commands/new.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { validateProjectName } from '../utilities/validate-project-name';
import { oneLine } from 'common-tags';
import { SchematicAvailableOptions } from '../tasks/schematic-get-options';

const { cyan } = chalk;

const Command = require('../ember-cli/lib/models/command');
const SilentError = require('silent-error');

Expand Down Expand Up @@ -153,6 +155,28 @@ const NewCommand = Command.extend({
commandOptions.skipGit = commandOptions.skipGit === undefined ? false : commandOptions.skipGit;

return initTask.run(commandOptions, rawArgs);
},

printDetailedHelp: function (): string | Promise<string> {
const collectionName = this.getCollectionName();
const schematicName = CliConfig.getValue('defaults.schematics.newApp');
const SchematicGetHelpOutputTask = require('../tasks/schematic-get-help-output').default;
const getHelpOutputTask = new SchematicGetHelpOutputTask({
ui: this.ui,
project: this.project
});
return getHelpOutputTask.run({
schematicName,
collectionName,
nonSchematicOptions: this.availableOptions.filter((o: any) => !o.hidden)
})
.then((output: string[]) => {
const outputLines = [
cyan(`ng new ${cyan('[name]')} ${cyan('<options...>')}`),
...output
];
return outputLines.join('\n');
});
}
});

Expand Down
69 changes: 69 additions & 0 deletions packages/@angular/cli/tasks/schematic-get-help-output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import chalk from 'chalk';
const Task = require('../ember-cli/lib/models/task');

const { cyan, grey } = chalk;

export interface SchematicGetHelpOptions {
collectionName: string;
schematicName: string;
nonSchematicOptions: any[];
}

export interface SchematicAvailableOptions {
name: string;
description: string;
aliases: string[];
type: any;
schematicType: any;
schematicDefault: any;
}

const hiddenOptions = [
'name',
'path',
'source-dir',
'app-root'
];

export default Task.extend({
run: function ({schematicName, collectionName, nonSchematicOptions}: SchematicGetHelpOptions):
Promise<string[]> {

const SchematicGetOptionsTask = require('./schematic-get-options').default;
const getOptionsTask = new SchematicGetOptionsTask({
ui: this.ui,
project: this.project
});
return Promise.all([getOptionsTask.run({
schematicName: schematicName,
collectionName: collectionName,
}), nonSchematicOptions])
.then(([availableOptions, nonSchematicOptions]: [SchematicAvailableOptions[], any[]]) => {
const output: string[] = [];
[...(nonSchematicOptions || []), ...availableOptions]
.filter(opt => hiddenOptions.indexOf(opt.name) === -1)
.forEach(opt => {
let text = cyan(` --${opt.name}`);
if (opt.schematicType) {
text += cyan(` (${opt.schematicType})`);
}
if (opt.schematicDefault) {
text += cyan(` (Default: ${opt.schematicDefault})`);
}
if (opt.description) {
text += ` ${opt.description}`;
}
output.push(text);
if (opt.aliases && opt.aliases.length > 0) {
const aliasText = opt.aliases.reduce(
(acc: string, curr: string) => {
return acc + ` -${curr}`;
},
'');
output.push(grey(` aliases: ${aliasText}`));
}
});
return output;
});
}
});