-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support dynamic show help commands (#140)
- Loading branch information
Showing
3 changed files
with
54 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,56 @@ | ||
import meow from 'meow'; | ||
import commandLineUsage from 'command-line-usage'; | ||
|
||
const getCommands = (store: any) => { | ||
const arr = []; | ||
for (const name in store ) { | ||
const desc = store[name].desc; | ||
arr.push({ | ||
colA: name, | ||
colB: desc | ||
}) | ||
} | ||
return arr; | ||
}; | ||
|
||
const showHelp = (commands: Array<Object>) => { | ||
|
||
const sections = [ | ||
{ | ||
header: 'Usage', | ||
content: '$ feflow [options] [command]' | ||
}, | ||
{ | ||
header: 'Commands', | ||
content: { | ||
data: commands, | ||
options: { | ||
maxWidth: 60 | ||
} | ||
} | ||
}, | ||
{ | ||
header: 'Options', | ||
optionList: [ | ||
{ | ||
name: 'version', | ||
description: 'Print version and exit successfully.' | ||
}, | ||
{ | ||
name: 'help', | ||
description: 'Print this help and exit successfully.' | ||
} | ||
] | ||
} | ||
]; | ||
const usage = commandLineUsage(sections); | ||
|
||
return usage; | ||
} | ||
|
||
module.exports = (ctx: any) => { | ||
ctx.commander.register('help', 'Help messages', () => { | ||
const cli = meow(` | ||
Usage: feflow [options] [command] | ||
Commands: | ||
init Choose a boilerplate to initialize project. | ||
install <plugin> Install a plugin or a yeoman generator. | ||
uninstall <plugin> Uninstall a plugin or a yeoman generator. | ||
lint <folder> Lint files or a folder. | ||
dev Local development. | ||
build Build and package. | ||
Options: | ||
--version, -[v] Print version and exit successfully. | ||
--help, -[h] Print this help and exit successfully. | ||
--list, -[l] Print all all plugins installed. | ||
Report bugs to https://github.com/Tencent/feflow. | ||
`); | ||
|
||
return cli.showHelp(0); | ||
const commands = getCommands(ctx.commander.store); | ||
const usage = showHelp(commands); | ||
console.log(usage); | ||
}); | ||
}; |