-
-
Notifications
You must be signed in to change notification settings - Fork 433
feat(cli): add Command.withConditionalBehavior for predicate based wrapping of commands #5708
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: 7e62945 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
3a0ff98 to
40d6e12
Compare
|
@ryanbas21 - thanks for the PR! I'm not sure about having a separate I think it would be nicer if a combinator could be exposed that would allow you to wrap a command and show the wizard mode based on a predicate. |
40d6e12 to
1ad7506
Compare
@IMax153 good feedback. Re-implemented it in this way. Let me know what you think? |
5bc8ffb to
db385a7
Compare
…mand behaviors
Introduces a composable combinator approach for adding conditional behaviors to commands.
Instead of having separate runWith* methods, this provides a single, extensible pattern.
Key features:
- Command.withConditionalBehavior() wraps commands with conditional behavior
- Predicate function determines when behavior should trigger
- Supports built-in "wizard" mode or custom behavior functions
- Fully composable with other Command combinators via .pipe()
- Backwards compatible with existing --wizard flag
Example usage:
```typescript
const command = Command.make("greet", {
name: Options.text("name")
}, ({ name }) => Effect.log(`Hello, ${name}!`))
.pipe(
Command.withConditionalBehavior(
(args) => args.length <= 1, // Run wizard when no args provided
"wizard"
)
)
Command.run(command, { name: "MyApp", version: "1.0.0" })
```
This design avoids API explosion (runWithWizard, runWithHelp, etc.) and follows
functional composition patterns. The same combinator can be extended for other
conditional behaviors like help display, validation, or custom prompting.
Fixes Effect-TS#5699
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
db385a7 to
7e62945
Compare
Type
Description
This PR introduces a composable combinator approach for adding conditional behaviors to commands based on CLI arguments.
Rather than adding separate runWith* methods for each conditional behavior (which would lead to API explosion with runWithWizard, runWithHelp, runWithValidation, etc.), this PR provides a single, extensible combinator pattern that follows functional composition principles.
A combinator that wraps a command to conditionally trigger a behavior based on the provided predicate function:
Parameters:
Wizard mode on bare command:
Related