1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
//! Fast designing menus for your Rust CLI programs.
//!
//! This crates provides many procedural macros to easily build menus.
//! It uses the [`ezmenulib`](https://docs.rs/ezmenulib) library crate in its expansion.
//!
//! # Example
//!
//! Here is an example of how to use the `derive(Menu)` macro
//! (it takes the same example as the documentation of the `ezmenu` library):
//! ```
//! use ezmenu::Menu;
//!
//! #[derive(Menu)]
//! #[menu(title = "Hello there!")]
//! struct MyMenu {
//! #[menu(msg = "Give your name")]
//! name: String,
//! #[menu(msg = "Give a number")]
//! number: i32,
//! }
//!
//! fn main() {
//! let MyMenu { name, number } = MyMenu::from_menu();
//! println!("values provided: name={}, number={}", name, number);
//! }
//! ```
//!
//! This sample code prints the standard menu like above:
//!
//! ```text
//! Hello there!
//! * Give your name: Ahmad
//! * Give a number: 1000
//! values provided: name=Ahmad, number=1000
//! ```
//!
//! ## Format it as you wish
//!
//! You can apply several formatting rules on a menu or on a field specifically.
//! You can edit:
//! * the chip: `* ` by default.
//! * the prefix: `: ` by default.
//! * insert a new line before prefix and user input: `false` by default.
//! * display default values or not: `true` by default.
//!
//! ### Example
//!
//! For a custom format on a field and a main formatting rule on a menu, you can build this with:
//! ```rust
//! #[derive(Menu)]
//! #[menu(chip = "==> ")]
//! struct License {
//! author: String,
//! #[menu(chip = "--> ")]
//! project_name: String,
//! date: u16,
//! }
//! ```
//!
//! The custom `==> ` chip will be applied on every field except those with custom formatting rules,
//! In this case, it will format the text like above:
//!
//! ```text
//! ==> Authors: ...
//! --> Project name: ...
//! ==> Date: ...
//! ```
//!
//! ## Skip fields with default values
//!
//! You can provide a default input value to a field with the `default` attribute:
//! ```rust
//! #[derive(Menu)]
//! struct License {
//! #[menu(default = 2022)]
//! date: u16,
//! // ...
//! }
//! ```
//!
//! If the user provided an incorrect input, the program will not re-ask a value to the user,
//! but will directly return the default value instead.
//!
//! By default, the default value is visible. If you want to hide it, you can do so
//! with formatting rules:
//! ```rust
//! #[derive(Menu)]
//! #[menu(display_default = false)] // <-- applied on all the fields
//! struct License {
//! #[menu(default = 2022, display_default = false)] // <-- applied on the field specifically
//! date: u16,
//! // ...
//! }
//! ```
//!
//! ## Use custom value types
//!
//! If the user has to provide a value which corresponds to your specific type,
//! you can add the `parsed` feature in your `Cargo.toml`:
//!
//! ```toml
//! [dependencies.ezmenu]
//! version = "0.2"
//! features = ["parsed"]
//! ```
//! Therefore, you only need to add the `ezmenu::parsed` attribute on that type.
//!
//! ### Example
//!
//! ```
//! #[ezmenu::parsed]
//! enum Type {
//! MIT,
//! BSD,
//! GPL,
//! }
//!
//! #[derive(Menu)]
//! struct License {
//! author: String,
//! #[menu(default = "mit")] // <-- you can still use the default attribute
//! ty: Type,
//! }
//! ```
//!
//! ## Provided custom value types
//!
//! The EZMenu library already provides
//! [custom value types](https://docs.rs/ezmenulib/latest/ezmenulib/#provided-custom-value-types)
//! to handle user input.
//!
//! ### Example
//!
//! ```
//! use ezmenulib::{MenuBool, MenuVec};
//!
//! #[derive(Menu)]
//! struct License {
//! authors: MenuVec<String>,
//! #[menu(msg = "Are you sure...????")]
//! is_sure: MenuBool,
//! // ...
//! }
//! ```
//!
//! ## Features
//!
//! This crate includes many features to allow you control your project building.
//!
//! For instance, the `"derive"` feature unlocks the `derive(Menu)` macro and is set by default,
//! and the `"parsed"` feature unlocks the `ezmenu::parsed` attribute macro.
//!
//! For example, if you only need to use the `parsed` feature to implement `FromStr` trait
//! on a type, you can do so by adding this to your `Cargo.toml` file:
//! ```toml
//! [dependencies.ezmenu]
//! default-features = false
//! features = ["parsed"]
//! version = "0.2"
//! ```
//!
//! Then you can add `#[ezmenu::parsed]` on that type and you'll be done :D
/// The `derive(Menu)` procedural macro.
///
/// It allows to easily build CLI menus, by using the [`ezmenulib`](https://docs.rs/ezmenulib/) crate.
///
/// ## Example
///
/// ```
/// use ezmenu::lib::MenuVec;
/// use ezmenu::MenuVec;
///
/// #[derive(Menu)]
/// #[menu(
/// title = "mkLicense program",
/// chip = "--> Give the "
/// prefix = ">> ",
/// new_line = true,
/// )]
/// struct License {
/// #[menu(msg = "authors name separated by spaces")]
/// authors: MenuVec<String>,
///
/// #[menu(msg = "project name")]
/// proj_name: String,
///
/// #[menu(msg = "project year", default = 2022)]
/// year: u16,
/// }
/// ```
pub use Menu;
/// The attribute simply implements the `FromStr` trait on a type.
///
/// ## Example
///
/// ```
/// #[ezmenu::parsed]
/// enum Type {
/// MIT,
/// GPL,
/// BSD,
/// }
///
/// #[derive(Menu)]
/// struct License {
/// #[menu(msg("Give the type of the license"))]
/// ty: Type,
/// }
/// ```
pub use parsed;
/// The re-exportation of the [`ezmenulib`](https://docs.rs/ezmenulib/)
/// crate for the macro expansion.