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
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
//! Add command for scaffolding new UI windows.
//!
//! This module provides the `dampen add --ui <window_name>` command that generates
//! UI window files (`.rs` and `.dampen`) based on templates.
//!
//! # Overview
//!
//! The `add` command scaffolds new UI windows for Dampen applications by:
//! - Generating a Rust module with model, handlers, and AppState
//! - Creating a corresponding `.dampen` XML file with basic UI layout
//! - Validating window names and output paths
//! - Preventing accidental file overwrites
//!
//! # Usage
//!
//! ## Basic Usage
//!
//! Create a new window in the default location (`src/ui/`):
//!
//! ```bash
//! dampen add --ui settings
//! ```
//!
//! This generates:
//! - `src/ui/settings.rs` - Rust module with Model and handlers
//! - `src/ui/settings.dampen` - XML UI definition
//!
//! ## Custom Output Directory
//!
//! Specify a custom output directory with `--path`:
//!
//! ```bash
//! dampen add --ui order_form --path "src/ui/orders"
//! ```
//!
//! This generates files in `src/ui/orders/`:
//! - `src/ui/orders/order_form.rs`
//! - `src/ui/orders/order_form.dampen`
//!
//! ## Window Name Conventions
//!
//! Window names are automatically converted to proper case:
//! - Input: `UserProfile` → Files: `user_profile.rs`, `user_profile.dampen`
//! - Input: `settings` → Files: `settings.rs`, `settings.dampen`
//!
//! # Generated Code Structure
//!
//! The generated Rust module includes:
//! - `Model` struct with `#[derive(UiModel)]` for data binding
//! - `create_app_state()` function that returns configured `AppState<Model>`
//! - `create_handler_registry()` with sample event handlers
//! - Auto-loading via `#[dampen_ui]` macro
//!
//! The generated XML includes:
//! - Basic column layout with text and button widgets
//! - Data binding example (`{message}`)
//! - Event handler hookup (`on_click="on_action"`)
//!
//! # After Generation
//!
//! 1. Add the module to `src/ui/mod.rs`:
//! ```rust,ignore
//! pub mod settings;
//! ```
//!
//! 2. Validate the XML:
//! ```bash
//! dampen check
//! ```
//!
//! 3. Use in your application:
//! ```rust,ignore
//! use ui::settings;
//! let state = settings::create_app_state();
//! ```
//!
//! # Error Handling
//!
//! The command validates:
//! - Project context (must be a Dampen project with `dampen-core` dependency)
//! - Window name (must be valid Rust identifier, not a reserved keyword)
//! - Output path (must be relative, within project bounds)
//! - File conflicts (prevents overwriting existing files)
//!
//! # Examples
//!
//! ```bash
//! # Create a settings window
//! dampen add --ui settings
//!
//! # Create an admin dashboard in a subdirectory
//! dampen add --ui dashboard --path "src/ui/admin"
//!
//! # Create an order form
//! dampen add --ui OrderForm
//! # → Generates: order_form.rs, order_form.dampen
//! ```
use Args;
// Export error types (Phase 2 complete)
pub use ;
// Export template types (Phase 2 complete)
pub use ;
// Export validation types (Phase 3-4 complete)
pub use ;
// Export generation types (Phase 5)
pub use ;
// Types will be exported as they're implemented in later phases
// pub use validation::{TargetPath};
/// Arguments for the `dampen add` command.
///
/// # Examples
///
/// ```bash
/// # Add a window in default location (src/ui/)
/// dampen add --ui settings
///
/// # Add a window in custom location
/// dampen add --ui admin_panel --path "src/ui/admin"
/// ```
///
/// # Fields
///
/// - `ui`: Window name (converted to snake_case for filenames)
/// - `path`: Custom output directory (relative to project root)
/// Execute the add command.
///
/// This generates UI window files based on validated inputs.
///
/// # Process
///
/// 1. **Detect project**: Validates this is a Dampen project
/// 2. **Validate name**: Checks window name is valid identifier
/// 3. **Resolve path**: Determines output directory (default or custom)
/// 4. **Generate files**: Creates .rs and .dampen files from templates
/// 5. **Report success**: Shows file paths and next steps
///
/// # Errors
///
/// Returns `Err(String)` if:
/// - Not in a Dampen project (no `dampen-core` in Cargo.toml)
/// - Window name is invalid (empty, starts with number, reserved keyword)
/// - Output path is invalid (absolute, escapes project)
/// - Files already exist (prevents overwriting)
/// - I/O errors occur during file creation
///
/// # Examples
///
/// ```no_run
/// use dampen_cli::commands::add::{AddArgs, execute};
///
/// let args = AddArgs {
/// ui: Some("settings".to_string()),
/// path: None,
/// no_integrate: false,
/// };
///
/// match execute(&args) {
/// Ok(()) => println!("Window created successfully"),
/// Err(e) => eprintln!("Error: {}", e),
/// }
/// ```