Skip to content
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

Closed
wants to merge 3 commits into from
Closed

Add commands option #205

wants to merge 3 commits into from

Conversation

skoshx
Copy link

@skoshx skoshx commented Mar 4, 2022

This commit adds support for subcommands.

Fixes #69

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.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use tab-indentation.

Copy link
Owner

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({
Copy link
Owner

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: {
Copy link
Owner

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.

Copy link
Owner

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: {}});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass helpText in options.

Unicorn command
Usage:
foo unicorn <input>
`,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tab-indentation.

#!/usr/bin/env node
import meow from '../../index.js';

const subcommand = (helpText, options = {}) => meow({
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
})
}
```
*/
Copy link
Owner

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 skoshx requested a review from sindresorhus March 11, 2022 12:18
@I-Want-ToBelieve
Copy link

@skoshx This is a very useful feature, this thread seems to have stalled for a long time, is there any progress now?

@skoshx
Copy link
Author

skoshx commented Jun 3, 2022

@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

@skoshx
Copy link
Author

skoshx commented Jul 24, 2022

Closing in favor of PR #211

@skoshx skoshx closed this Jul 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support subcommands
3 participants