Add validators schema and code templates
This commit is contained in:
52
src/templates/node-yargs.handlebars
Normal file
52
src/templates/node-yargs.handlebars
Normal file
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import yargs from 'yargs';
|
||||
import { hideBin } from 'yargs/helpers';
|
||||
|
||||
const argv = yargs(hideBin(process.argv))
|
||||
.command('{{spec.name}}', '{{spec.description}}', (yargs) => {
|
||||
return yargs
|
||||
.option('version', {
|
||||
alias: 'v',
|
||||
type: 'boolean',
|
||||
description: 'Show version'
|
||||
})
|
||||
{{#each spec.globalOptions}}
|
||||
.option('{{name}}', {
|
||||
{{#if short}}alias: '{{short}}',{{/if}}
|
||||
type: '{{type}}',
|
||||
description: '{{escape description}}'{{#if default}}, default: '{{defaultValue}}'{{/if}}
|
||||
})
|
||||
{{/each}}
|
||||
.command('{{#each spec.commands}}{{name}}{{#unless @last}}', '{{@index}}', {{/unless}}{{/each}}', '{{escape description}}', (yargs) => {
|
||||
return yargs
|
||||
{{#each ../spec.commands}}
|
||||
.command('{{name}}', '{{escape description}}', (yargs) => {
|
||||
return yargs
|
||||
{{#each arguments}}
|
||||
.positional('{{name}}', {
|
||||
describe: '{{escape description}}',
|
||||
type: '{{type}}'{{#if required}}, demandOption: true{{/if}}
|
||||
})
|
||||
{{/each}}
|
||||
{{#each options}}
|
||||
.option('{{name}}', {
|
||||
{{#if short}}alias: '{{short}}',{{/if}}
|
||||
describe: '{{escape description}}',
|
||||
type: '{{type}}'
|
||||
})
|
||||
{{/each}}
|
||||
}, (argv) => {
|
||||
console.log('Running {{name}} command');
|
||||
})
|
||||
{{/each}}
|
||||
}, (argv) => {
|
||||
if (argv.version) {
|
||||
console.log('{{spec.name}} v{{spec.version}}');
|
||||
} else {
|
||||
console.log('Use --help to see available commands');
|
||||
}
|
||||
})
|
||||
})
|
||||
.help()
|
||||
.parse();
|
||||
Reference in New Issue
Block a user