wizify

Crates.iowizify
lib.rswizify
version0.0.2
created_at2025-05-25 05:53:50.950989+00
updated_at2025-05-28 03:18:30.834575+00
descriptionA macro library for generating a creation wizard from a struct
homepage
repositoryhttps://github.com/CalSimmon/wizify-rs
max_upload_size
id1688037
size19,321
Caleb Simmons (CalSimmon)

documentation

README

Github Repo Crates.io Docs.rs

wizify

Quick and simple tool to generate a creation wizard based directly off a struct. Uses your field name along with dialoguer to provide basic creation and validation tasks. Currently, this only works with structs, but in the future, I want to add in enums for selection prompts.

If you want to see the library in action, clone the repository and run the test-wiz project.

[!WARNING] This project is under active development. Each release may have breaking changes as I develop the library.

Table of Contents

Usage

In order to generate a creation wizard from a struct, you need to use the Wizard derive macro. Here's an example:

#[derive(Wizard, Debug)]
#[wizard(
    begin_msg = "✨ Hello, and welcome to the wizify creation wizard 🐧\n\n",
    closing_msg = "\nThat was the demonstration of the wizify creation wizard. 🌛",
    prefix = " ❓ => "
)]
struct Testing {
    #[wizard(prompt = "Enter your name (Optional)")]
    name: Option<String>,
    #[wizard(prompt = "Enter your favorite color")]
    favorite_color: String,
    #[wizard(prompt = "Enter your favorite number between 0 and 9", validation = input < 10)]
    favorite_number: i32,
}

As of right now, this only supports basic primitives, but in the future I would like to support custom struct fields as well.

Derive

Using #[derive(Wizard)] on the stuct will give you basic functionality right out of the box, but there are some options to make a beautiful wizard with ease.

Struct Options

On the struct level, there are a couple options that will apply to the wizard as a whole.

Opening / Closing Messages

By adding #[wizard(begin_msg = "<message>")] or #[wizard(begin_msg = <message>)] to your struct parameters, you can add a message at the beginning or the end of your creation wizard. These will each be printed once over the entire wizard. By default, these messages do not include any styling, so you will need to add any newlines that you want.

Prefixes for Your Prompts

If you want to add a custom prefix to all prompts in your wizard, you can do that by adding the #[wizard(prefix = "<prefix>")] to your struct parameters. This will apply to the beginning of every prompt for your fields.

These two options added together will look like this when run:

✨ Hello, and welcome to the wizify creation wizard 🐧

 ❓ => name: Test
 ❓ => favorite_color: color
 ❓ => favorite_number: 0

That was the demonstration of the wizify creation wizard. 🌛

Field Options

Each of the fields can also be customized to use custom prompts and validation.

Custom Prompts

Using #[wizard(prompt = "<prompt>")] allows you to override the default which is to use the name of the field. This will only work for the annotated field.

Custom Validation

Using #[wizard(validation = <expression>)] allows you to add in extra validation for your prompt.

[!NOTE] By default, dialoguer will always check the type of your prompt, so you do not need to include that in the validation.

To write a validation, use input to mean what the user inputs into the dialoguer prompt, and your validation will be evaluated based on that. For instance, in the example above we use validation = input < 10. This will get expanded into:

if input < 10 {
    Ok(())
} else {
    Err("This input is not valid...")
}

Putting these together, the above earlier example will show this as the full wizard:

✨ Hello, and welcome to the wizify creation wizard 🐧

 ❓ => Enter your name (Optional): Test
 ❓ => Enter your favorite color: color
 ❓ => Enter your favorite number between 0 and 9: 0

That was the demonstration of the wizify creation wizard. 🌛

Future Plans

There are a number of upgrades I would like to accomplish in the near future.

  • Allowing nested structs when all implement wizard trait
  • Add enum parsing for selection prompts
  • Ignore options for fields
  • Custom struct builders post wizard
  • Options to handle vector types
Commit count: 19

cargo fmt