derive_wizard_types/
question.rs

1#[derive(Debug, Clone)]
2pub struct Question {
3    /// The unique identifier for the question.
4    id: Option<String>,
5
6    /// The field name.
7    name: String,
8
9    /// The prompt message to display.
10    prompt: String,
11
12    kind: QuestionKind,
13}
14
15impl Question {
16    /// Create a new question with the given id, name, prompt, and kind.
17    pub fn new(id: Option<String>, name: String, prompt: String, kind: QuestionKind) -> Self {
18        Self {
19            id,
20            name,
21            prompt,
22            kind,
23        }
24    }
25
26    pub fn id(&self) -> Option<&str> {
27        self.id.as_deref()
28    }
29
30    pub fn name(&self) -> &str {
31        &self.name
32    }
33
34    pub fn prompt(&self) -> &str {
35        &self.prompt
36    }
37
38    pub fn kind(&self) -> &QuestionKind {
39        &self.kind
40    }
41}
42
43/// Possible question kinds which a wizard may ask.
44#[derive(Debug, Clone)]
45pub enum QuestionKind {
46    /// A text input question for string values.
47    Input(InputQuestion),
48
49    /// A multi-line text input.
50    Multiline(MultilineQuestion),
51
52    /// A password/masked input question.
53    Masked(MaskedQuestion),
54
55    /// A number input question (integers).
56    Int(IntQuestion),
57
58    /// A number input question (floating point).
59    Float(FloatQuestion),
60
61    /// A yes/no confirmation question.
62    Confirm(ConfirmQuestion),
63
64    /// A nested interview (for composite types that implement Wizard).
65    Nested(NestedQuestion),
66}
67
68/// Configuration for a nested interview question.
69#[derive(Debug, Clone)]
70pub struct NestedQuestion {
71    /// The type path of the nested wizard type.
72    pub type_path: String,
73}
74
75/// Configuration for a text input question.
76#[derive(Debug, Clone)]
77pub struct InputQuestion {
78    /// Optional default value.
79    pub default: Option<String>,
80
81    /// Validation function to call on each keystroke.
82    pub validate_on_key: Option<String>,
83
84    /// Validation function to call on submission.
85    pub validate_on_submit: Option<String>,
86}
87
88/// Configuration for a multi-line text editor question.
89#[derive(Debug, Clone)]
90pub struct MultilineQuestion {
91    /// Optional default value.
92    pub default: Option<String>,
93
94    /// Validation function to call on each keystroke.
95    pub validate_on_key: Option<String>,
96
97    /// Validation function to call on submission.
98    pub validate_on_submit: Option<String>,
99}
100
101/// Configuration for a password/masked input question.
102#[derive(Debug, Clone)]
103pub struct MaskedQuestion {
104    /// The masking character (default: '*').
105    pub mask: Option<char>,
106
107    /// Validation function to call on each keystroke.
108    pub validate_on_key: Option<String>,
109
110    /// Validation function to call on submission.
111    pub validate_on_submit: Option<String>,
112}
113
114/// Configuration for an integer input question.
115#[derive(Debug, Clone)]
116pub struct IntQuestion {
117    /// Optional default value
118    pub default: Option<i64>,
119
120    /// Optional minimum value
121    pub min: Option<i64>,
122
123    /// Optional maximum value
124    pub max: Option<i64>,
125
126    /// Validation function to call on each keystroke.
127    pub validate_on_key: Option<String>,
128
129    /// Validation function to call on submission.
130    pub validate_on_submit: Option<String>,
131}
132
133/// Configuration for a floating-point input question.
134#[derive(Debug, Clone)]
135pub struct FloatQuestion {
136    /// Optional default value.
137    pub default: Option<f64>,
138
139    /// Optional minimum value
140    pub min: Option<f64>,
141
142    /// Optional maximum value
143    pub max: Option<f64>,
144
145    /// Validation function to call on each keystroke.
146    pub validate_on_key: Option<String>,
147
148    /// Validation function to call on submission.
149    pub validate_on_submit: Option<String>,
150}
151
152/// Configuration for a yes/no confirmation question.
153#[derive(Debug, Clone)]
154pub struct ConfirmQuestion {
155    /// Default value (true for yes, false for no)
156    pub default: bool,
157}