wizify/
lib.rs

1//! # wizify
2//! 
3//! Quick and simple tool to generate a creation wizard based directly off a struct. Uses your field name along with dialoguer to provide
4//! basic creation and validation tasks. Currently, this only works with structs, but in the future, I want to add in enums for selection 
5//! prompts.
6//! 
7//! ⚠️ WARNING ⚠️ This project is under active development. Each release may have breaking changes as I develop the library.
8//! 
9//! ## Usage
10//! In order to generate a creation wizard from a struct, you need to use the `Wizard` derive macro. Here's an example:
11//! 
12//! ```rust
13//! #[derive(Wizard, Debug)]
14//! #[wizard(
15//!     begin_msg = "✨ Hello, and welcome to the wizify creation wizard 🐧\n\n",
16//!     closing_msg = "\nThat was the demonstration of the wizify creation wizard. 🌛",
17//!     prefix = " ❓ => "
18//! )]
19//! struct Testing {
20//!     #[wizard(prompt = "Enter your name (Optional)")]
21//!     name: Option<String>,
22//!     #[wizard(prompt = "Enter your favorite color")]
23//!     favorite_color: String,
24//!     #[wizard(prompt = "Enter your favorite number between 0 and 9", validation = input < 10)]
25//!     favorite_number: i32,
26//! }
27//! ```
28//! As of right now, this only supports basic primitives, but in the future I would like to support custom struct fields as well.
29//!
30//! #### *For information on the specifics of the derive options, see the derive macro documentation below.*
31
32
33/// Struct macro for creating wizard
34///
35/// ## Derive
36///
37/// Using `#[derive(Wizard)]` on the stuct will give you basic functionality right out of the box, but there are some options to make a 
38/// beautiful wizard with ease.
39/// 
40/// ### Struct Options
41/// On the struct level, there are a couple options that will apply to the wizard as a whole.
42/// 
43/// #### Opening / Closing Messages
44/// 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
45/// end of your creation wizard. These will each be printed once over the entire wizard. By default, these messages do not include any 
46/// styling, so you will need to add any newlines that you want.
47/// 
48/// #### Prefixes for Your Prompts
49/// 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
50/// struct parameters. This will apply to the beginning of every prompt for your fields.
51/// 
52/// These two options added together will look like this when run:
53/// 
54/// ```rust
55/// ✨ Hello, and welcome to the wizify creation wizard 🐧
56/// 
57///  ❓ => name: Test
58///  ❓ => favorite_color: color
59///  ❓ => favorite_number: 0
60/// 
61/// That was the demonstration of the wizify creation wizard. 🌛
62/// ```
63/// 
64/// ### Field Options
65/// Each of the fields can also be customized to use custom prompts and validation.
66/// 
67/// #### Custom Prompts
68/// 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
69/// annotated field.
70/// 
71/// #### Custom Validation
72/// Using `#[wizard(validation = <expression>)]` allows you to add in extra validation for your prompt. 
73/// 
74/// 📝 NOTE
75/// By default, dialoguer will always check
76/// the type of your prompt, so you do not need to include that in the validation. 
77/// 
78/// 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.
79/// For instance, in the example above we use `validation = input < 10`. This will get expanded into:
80/// 
81/// ```rust
82/// if input < 10 {
83///     Ok(())
84/// } else {
85///     Err("This input is not valid...")
86/// }
87/// ```
88/// Putting these together, the above earlier example will show this as the full wizard:
89/// 
90/// ```rust
91/// ✨ Hello, and welcome to the wizify creation wizard 🐧
92/// 
93///  ❓ => Enter your name (Optional): Test
94///  ❓ => Enter your favorite color: color
95///  ❓ => Enter your favorite number between 0 and 9: 0
96/// 
97/// That was the demonstration of the wizify creation wizard. 🌛
98/// ```
99pub use wizify_derive::*;
100
101/// Trait is populated using the Wizard derive annotation
102pub trait Wizard {
103    fn wizard() -> Self;
104}