-
-
Notifications
You must be signed in to change notification settings - Fork 151
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
Add commands
option
#205
Add commands
option
#205
Conversation
This commit adds support for subcommands.
index.d.ts
Outdated
@@ -68,6 +70,30 @@ export interface Options<Flags extends AnyFlags> { | |||
*/ | |||
readonly flags?: Flags; | |||
|
|||
/** | |||
Define subcommands. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use tab-indentation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The description needs to be more extensive. It should describe how it works (that it doesn't actually call any commands for you, etc).
index.d.ts
Outdated
@example | ||
``` | ||
commands: { | ||
unicorn: (helpText, options) => meow({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helpText
argument is moot. helpText
can already be passed in options
.
index.d.ts
Outdated
|
||
@example | ||
``` | ||
commands: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example should be complete and runnable. I think it's better to define the subcommand function at the top-level, for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example should also illustrate how one might check for and call code for the subcommand.
index.js
Outdated
continue; | ||
} | ||
|
||
commands[command] = meowInstance(helpText, {...options, argv: process.argv.slice(3), commands: {}}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass helpText
in options
.
test/fixtures/fixture-commands.js
Outdated
Unicorn command | ||
Usage: | ||
foo unicorn <input> | ||
`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tab-indentation.
test/fixtures/fixture-commands.js
Outdated
#!/usr/bin/env node | ||
import meow from '../../index.js'; | ||
|
||
const subcommand = (helpText, options = {}) => meow({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const subcommand = (helpText, options = {}) => meow({ | |
const subcommand = (helpText, options) => meow({ |
The options
should be guaranteed. Make sure the code guarantees it to exist.
index.d.ts
Outdated
}) | ||
} | ||
``` | ||
*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also needs to be documented in the readme.
@skoshx This is a very useful feature, this thread seems to have stalled for a long time, is there any progress now? |
@backtolife2021 I made the changes requested by Sindre, other than that everything is good to go, just waiting for Sindre's review. friendly bump :) @sindresorhus |
Closing in favor of PR #211 |
This commit adds support for subcommands.
Fixes #69