refactor: command help

This commit is contained in:
cha0s 2024-01-24 00:55:34 -06:00
parent 1d06f4a272
commit 63583f53c4
6 changed files with 32 additions and 30 deletions

View File

@ -62,9 +62,6 @@ program
cmd.addOption(options[i]); cmd.addOption(options[i]);
} }
cmd.action(forwardProcessCode(action)); cmd.action(forwardProcessCode(action));
if (help) {
cmd.addHelpText('after', `\n${help}`);
}
} }
// Parse commandline. // Parse commandline.
program.parse(process.argv); program.parse(process.argv);

View File

@ -26,7 +26,7 @@ exports.commands = (program, flecks) => {
options: [ options: [
program.createOption('-d, --dev-dependency', 'add to dev dependencies'), program.createOption('-d, --dev-dependency', 'add to dev dependencies'),
], ],
description: 'add a fleck to your application', description: 'Add a fleck to your application.',
action: async ({devDependency}, fleck) => { action: async ({devDependency}, fleck) => {
const args = []; const args = [];
if (['bun', 'yarn'].includes(packageManager)) { if (['bun', 'yarn'].includes(packageManager)) {
@ -41,7 +41,7 @@ exports.commands = (program, flecks) => {
}, },
}, },
clean: { clean: {
description: 'remove node_modules, lock file, and build artifacts', description: 'Remove node_modules, lock file, and build artifacts.',
action: () => { action: () => {
rimraf.sync(join(flecksRoot, 'dist')); rimraf.sync(join(flecksRoot, 'dist'));
rimraf.sync(join(flecksRoot, 'node_modules')); rimraf.sync(join(flecksRoot, 'node_modules'));
@ -75,7 +75,7 @@ exports.commands = (program, flecks) => {
program.createOption('-w, --watch', 'watch for changes') program.createOption('-w, --watch', 'watch for changes')
.implies({production: false}), .implies({production: false}),
], ],
description: 'build a target in your application', description: 'Build a target in your application.',
action: async (target, opts) => { action: async (target, opts) => {
const { const {
hot, hot,
@ -104,7 +104,7 @@ exports.commands = (program, flecks) => {
}; };
} }
commands.lint = { commands.lint = {
description: 'run linter', description: 'Run ESLint.',
args: [], args: [],
action: async () => { action: async () => {
const promises = []; const promises = [];

View File

@ -22,7 +22,15 @@ module.exports = (program, flecks) => {
const siteDirArgument = program.createArgument('[siteDir]', 'Docusaurus directory'); const siteDirArgument = program.createArgument('[siteDir]', 'Docusaurus directory');
siteDirArgument.defaultValue = 'website'; siteDirArgument.defaultValue = 'website';
commands.docusaurus = { commands.docusaurus = {
description: 'create a documentation website for this project', description: [
'Create a documentation website for this project.',
'',
'The `build` and `start` subcommands are sugar on top of the corresponding Docusaurus commands.',
'',
'The `create` subcommand will create a documentation website starter template for you at `siteDir`',
"if `siteDir` doesn't already exist (defaults to `website`). A `docusaurus.config.js`",
"starter configuration will also be copied to your `build` directory if it doesn't already exist.",
].join('\n'),
action: async (subcommand, siteDir) => { action: async (subcommand, siteDir) => {
const resolvedSiteDir = resolveSiteDir(siteDir); const resolvedSiteDir = resolveSiteDir(siteDir);
let siteDirExisted = false; let siteDirExisted = false;
@ -79,13 +87,6 @@ module.exports = (program, flecks) => {
.choices(['build', 'create', 'start']), .choices(['build', 'create', 'start']),
siteDirArgument, siteDirArgument,
], ],
help: [
'The `build` and `start` subcommands are sugar on top of the corresponding Docusaurus commands.',
'',
'The `create` subcommand will create a documentation website starter template for you at `siteDir`',
"if `siteDir` doesn't already exist (defaults to `website`). A `docusaurus.config.js`",
"starter configuration will also be copied to your `build` directory if it doesn't already exist.",
].join('\n'),
}; };
return commands; return commands;
}; };

View File

@ -23,7 +23,11 @@ module.exports = (program, flecks) => {
program.createOption('-w, --watch', 'watch for changes'), program.createOption('-w, --watch', 'watch for changes'),
program.createOption('-v, --verbose', 'verbose output'), program.createOption('-v, --verbose', 'verbose output'),
], ],
description: 'run tests', description: [
'Run tests.',
'',
'The options are passed along to the `build` command.',
].join('\n'),
action: async (opts) => { action: async (opts) => {
const { const {
watch, watch,

View File

@ -14,7 +14,7 @@ module.exports = (program, flecks) => {
options: [ options: [
program.createOption('-r, --rlwrap', 'use rlwrap around socat'), program.createOption('-r, --rlwrap', 'use rlwrap around socat'),
], ],
description: 'connect to REPL', description: 'Connect to REPL.',
action: async (opts) => { action: async (opts) => {
const { const {
rlwrap, rlwrap,

View File

@ -31,7 +31,7 @@ Options:
``` ```
Usage: flecks build [options] [target] Usage: flecks build [options] [target]
build a target in your application Build a target in your application.
Arguments: Arguments:
target build target (choices: "fleck") target build target (choices: "fleck")
@ -48,7 +48,7 @@ Options:
``` ```
Usage: flecks clean [options] Usage: flecks clean [options]
remove node_modules, lock file, and build artifacts Remove node_modules, lock file, and build artifacts.
Options: Options:
-h, --help display help for command -h, --help display help for command
@ -60,7 +60,13 @@ Options:
``` ```
Usage: flecks docusaurus [options] <subcommand> [siteDir] Usage: flecks docusaurus [options] <subcommand> [siteDir]
create a documentation website for this project Create a documentation website for this project.
The `build` and `start` subcommands are sugar on top of the corresponding Docusaurus commands.
The `create` subcommand will create a documentation website starter template for you at `siteDir`
if `siteDir` doesn't already exist (defaults to `website`). A `docusaurus.config.js`
starter configuration will also be copied to your `build` directory if it doesn't already exist.
Arguments: Arguments:
subcommand Docusaurus command to run (choices: "build", "create", "start") subcommand Docusaurus command to run (choices: "build", "create", "start")
@ -68,12 +74,6 @@ Arguments:
Options: Options:
-h, --help display help for command -h, --help display help for command
The `build` and `start` subcommands are sugar on top of the corresponding Docusaurus commands.
The `create` subcommand will create a documentation website starter template for you at `siteDir`
if `siteDir` doesn't already exist (defaults to `website`). A `docusaurus.config.js`
starter configuration will also be copied to your `build` directory if it doesn't already exist.
``` ```
### `lint` ### `lint`
@ -81,7 +81,7 @@ starter configuration will also be copied to your `build` directory if it doesn'
``` ```
Usage: flecks lint [options] Usage: flecks lint [options]
run linter Run ESLint.
Options: Options:
-h, --help display help for command -h, --help display help for command
@ -93,7 +93,7 @@ Options:
``` ```
Usage: flecks repl [options] Usage: flecks repl [options]
connect to REPL Connect to REPL.
Options: Options:
-r, --rlwrap use rlwrap around socat -r, --rlwrap use rlwrap around socat
@ -105,16 +105,16 @@ Options:
``` ```
Usage: flecks test [options] Usage: flecks test [options]
run tests Run tests.
Options: Options:
-d, --no-production dev build -d, --no-production dev build
-w, --watch watch for changes -w, --watch watch for changes
-v, --verbose verbose output -v, --verbose verbose output
-h, --help display help for command -h, --help display help for command
```
The options are passed along to the `build` command. The options are passed along to the `build` command.
```
## Your commands ## Your commands