derive-wizard-0.4.0 has been yanked.
derive-wizard
A Rust procedural macro that automatically generates interactive CLI wizards from struct definitions using requestty.
Showcase
use Wizard;
Password Fields with #[mask]
For password inputs, use the convenient #[mask] attribute to hide user input:
use Wizard;
Long Text with #[editor]
For longer text input, use the #[editor] attribute to open the user's preferred text editor:
use Wizard;
Attributes
#[prompt("message")]- Required. The message to display to the user#[mask]- Optional. For String fields: enables password input (hidden text)#[editor]- Optional. For String fields: opens text editor for longer input#[validate_on_submit("function_name")]- Optional. Validates input when user submits#[validate_on_key("function_name")]- Optional. Validates input on every keystroke
Note: #[mask] and #[editor] are mutually exclusive and cannot be used on the same field.
Using the Builder API
The builder API provides a fluent interface for configuring and executing wizards:
use Wizard;
// Simple usage with default backend (requestty)
let config = wizard_builder.build;
println!;
// Edit configuration with defaults pre-filled
let updated_config = wizard_builder
.with_defaults
.build;
println!;
Additional examples:
use Wizard;
#
#
// With custom backend (e.g., requestty)
let backend = new;
let config = wizard_builder
.with_backend
.build;
println!;
// Combine defaults with custom backend
let backend = new;
let updated_config = wizard_builder
.with_defaults
.with_backend
.build;
println!;
When with_defaults() is used:
- For String fields: the current value is shown as a hint/placeholder
- For numeric fields (integers and floats): the current value is shown as default
- For bool fields: the current value is pre-selected
- For password (
#[mask]) and editor (#[editor]) fields: defaults are shown as hints (backend-dependent)
Supported Question Types
The #[derive(Wizard)] macro supports all 11 requestty question types:
| Rust Type | Default Question Type | Override Options | Returns |
|---|---|---|---|
String |
input |
#[mask] for password, #[editor] for text editor |
String |
bool |
confirm |
- | bool |
i8, i16, i32, i64, isize |
int |
- | i64 (cast to type) |
u8, u16, u32, u64, usize |
int |
- | i64 (cast to type) |
f32, f64 |
float |
- | f64 (cast to type) |
ListItem |
select |
- | ListItem |
ExpandItem |
expand |
- | ExpandItem |
Vec<ListItem> |
multi_select |
- | Vec<ListItem> |
Question Type Details
- input - Basic text input prompt (default for String)
- password - Hidden text input (use
#[mask]on String fields) - editor - Opens text editor for longer input (use
#[editor]on String fields) - confirm - Yes/No confirmation prompt (default for bool)
- int - Integer input (default for integer types)
- float - Floating point input (default for float types)
- select - Single selection from a list (default for ListItem)
- expand - Single selection with keyboard shortcuts (default for ExpandItem)
- multi_select - Multiple selection from a list (default for
Vec<ListItem>)
Note: The following question types are available in requestty but not currently exposed through attributes:
- raw_select - Single selection with index-based input
- order_select - Reorder items in a list
License
MIT OR Apache-2.0