beautify usage output
parent
e0bf9ed40d
commit
f40207195c
|
@ -84,5 +84,17 @@ function run(args) {
|
|||
}
|
||||
|
||||
module.exports = {
|
||||
run
|
||||
description: 'Generate a new api spec from a template.',
|
||||
usage: {
|
||||
options: {
|
||||
'--verbose, -v': 'Verbose output. Includes debugging information. (optional)',
|
||||
'--interactive, -i': 'Interactive mode. Generate spec with interactive input from user. (optional)',
|
||||
'--name': 'Name of the service.',
|
||||
'--description': 'Description of the service.',
|
||||
'--namespace': 'Namespace of the service. (optional)',
|
||||
'--baseurl': 'Base URL of the service. (optional)',
|
||||
}
|
||||
},
|
||||
run,
|
||||
|
||||
}
|
|
@ -16,7 +16,7 @@ module.exports = {
|
|||
run,
|
||||
usage: {
|
||||
options: {
|
||||
'-v, --verbose': 'verbose output. Includes name and description.',
|
||||
'-v, --verbose': 'Verbose output. Includes name and description.',
|
||||
}
|
||||
}
|
||||
}
|
|
@ -14,7 +14,6 @@ if(!command) {
|
|||
command = commands.help
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
command.run(args)
|
||||
}catch(err) {
|
||||
|
|
|
@ -1,16 +1,30 @@
|
|||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
|
||||
function printColumns(left, right) {
|
||||
let indent = 48 - left.length
|
||||
let result = left + ' ';
|
||||
for(let i = 0; i < indent; i++) {
|
||||
result += '.'
|
||||
}
|
||||
result += ' ' + right
|
||||
return result
|
||||
}
|
||||
|
||||
function printCommandUsage(command) {
|
||||
console.log(`- <${command.name}> ${command.description || ''}`)
|
||||
if(command.name === '?' || command.name === 'help') {
|
||||
return
|
||||
}
|
||||
console.log(`\n[${command.name}]\n${command.description || ''}`)
|
||||
if(command.usage && command.usage.options) {
|
||||
Object.entries(command.usage.options)
|
||||
.forEach(entry => console.log(`\t ${entry[0]} | ${entry[1]}`))
|
||||
.forEach(entry => console.log(`\t ${printColumns(entry[0], entry[1])}`))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function printCompleteUsage(commands) {
|
||||
Object.values(commands).forEach(printCommandUsage)
|
||||
Object.values(commands).sort((a, b) => a.name.localeCompare(b.name)).forEach(printCommandUsage)
|
||||
}
|
||||
|
||||
function load() {
|
||||
|
@ -24,6 +38,14 @@ function load() {
|
|||
|
||||
command.name = result.name || name
|
||||
command.printUsage = () => printCommandUsage(command)
|
||||
let run_command = command.run
|
||||
command.run = (args) => {
|
||||
if(args['?'] || args.help) {
|
||||
printCommandUsage(command)
|
||||
return
|
||||
}
|
||||
run_command(args)
|
||||
}
|
||||
|
||||
result[name] = command
|
||||
return result
|
||||
|
|
Loading…
Reference in New Issue