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
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
//! Command definitions for Nargo CLI.
//!
//! This module defines all available commands and their execution logic.
mod bridge;
mod build;
mod dev;
mod git;
mod init;
mod lsp;
mod package;
mod run;
mod test;
use clap::Subcommand;
use color_eyre::eyre::Result;
use std::path::PathBuf;
pub use git::{GitCommands, HookCommands};
/// Available Nargo commands.
#[derive(Debug, Subcommand)]
pub enum Commands {
/// Start development server with hot reload.
Dev {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Port to listen on.
#[arg(short, long, default_value_t = 3000)]
port: u16,
/// Enable integrated mock server.
#[arg(short, long)]
mock: bool,
/// Mock server port.
#[arg(long, default_value_t = 4000)]
mock_port: u16,
/// Mock directory.
#[arg(long, default_value = "mocks")]
mock_dir: PathBuf,
},
/// Build for production.
Build {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Output directory.
#[arg(short, long, default_value = "dist")]
out_dir: PathBuf,
},
/// Compile project (CaaS - Compiler as a Service).
Compile {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Enable watch mode.
#[arg(short, long)]
watch: bool,
},
/// Run monorepo tasks.
Run {
/// Task name to run.
task: String,
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Enable hybrid hot reload (Rust + TS).
#[arg(short = 'H', long)]
hybrid: bool,
/// Enable watch mode.
#[arg(short, long)]
watch: bool,
},
/// Git related operations (Native).
Git {
#[command(subcommand)]
subcommand: GitCommands,
},
/// Native Git Hooks management.
Hooks {
#[command(subcommand)]
subcommand: HookCommands,
},
/// Serve static files.
Serve {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Port to listen on.
#[arg(short, long, default_value_t = 3000)]
port: u16,
/// Directory to serve.
#[arg(default_value = "dist")]
dir: PathBuf,
},
/// Generate TS types from Rust structs.
Bridge {
/// Output directory for TS files.
#[arg(short, long, default_value = "packages/nargo/types")]
out_dir: PathBuf,
},
/// Initialize a new project.
Init(init::InitArgs),
/// Run tests.
Test {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Test file filter (glob pattern or file path).
filter: Option<String>,
/// Enable coverage collection.
#[arg(short, long)]
coverage: bool,
/// Generate report.
#[arg(long)]
report: bool,
/// Run tests in parallel.
#[arg(long, default_value_t = true)]
parallel: bool,
/// Test timeout in milliseconds.
#[arg(long, default_value_t = 5000)]
timeout: u64,
/// Watch mode.
#[arg(short, long)]
watch: bool,
},
/// Lint source files.
Lint {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Generate report.
#[arg(long)]
report: bool,
},
/// Format source files.
Format {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Write changes to files.
#[arg(short, long)]
write: bool,
/// Generate report.
#[arg(long)]
report: bool,
},
/// Audit project for security issues.
Audit {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Generate report.
#[arg(long)]
report: bool,
},
/// Benchmark performance.
Bench {
/// Sample file to benchmark.
#[arg(default_value = "src/App.nargo")]
file: PathBuf,
/// Number of iterations.
#[arg(short, long, default_value_t = 100)]
iterations: u32,
},
/// Run mock server (RaaS - Router as a Service).
Mock {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Port to listen on.
#[arg(short, long, default_value_t = 4000)]
port: u16,
/// Directory containing mock JSON files.
#[arg(short, long, default_value = "mocks")]
dir: PathBuf,
},
/// Start Language Server (LSP).
Lsp {
/// Listen on a specific port (HTTP/WebSocket).
#[arg(short, long, default_value_t = 5005)]
port: u16,
/// Use stdio for communication.
#[arg(long)]
stdio: bool,
},
/// Start MCP (Model Context Protocol) server.
Mcp {
/// Listen on a specific port.
#[arg(short, long, default_value_t = 5006)]
port: u16,
/// Use stdio for communication.
#[arg(long)]
stdio: bool,
},
/// Run all checks and generate comprehensive report.
Check {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
},
/// Add a dependency to the project.
Add {
/// Package name (with optional version, e.g., lodash@4.17.21).
package: String,
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Add as dev dependency.
#[arg(short = 'D', long)]
dev: bool,
/// Add as optional dependency.
#[arg(short, long)]
optional: bool,
/// Enable specific features.
#[arg(short = 'F', long)]
features: Vec<String>,
},
/// Remove a dependency from the project.
Remove {
/// Package name.
package: String,
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
},
/// Update dependencies.
Update {
/// Package name (optional, updates all if not specified).
package: Option<String>,
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Update to latest versions (ignore lock file).
#[arg(short, long)]
latest: bool,
},
/// Install dependencies from Nargo.toml.
Install {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Force reinstall all dependencies.
#[arg(short, long)]
force: bool,
/// Production only (skip dev dependencies).
#[arg(short = 'P', long)]
production: bool,
},
/// Migrate from package.json to Nargo.toml.
Migrate {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Keep original package.json.
#[arg(long)]
keep_original: bool,
},
/// Clean cache and build artifacts.
Clean {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Clean cache only.
#[arg(long)]
cache: bool,
/// Clean target directory only.
#[arg(long)]
target: bool,
},
/// Search for packages in the registry.
Search {
/// Search query.
query: String,
/// Maximum number of results.
#[arg(short, long, default_value_t = 10)]
limit: usize,
},
/// Publish package to registry.
Publish {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Target registry URL.
#[arg(short, long)]
registry: Option<String>,
/// Dry run (don't actually publish).
#[arg(long)]
dry_run: bool,
/// Access level (public or restricted).
#[arg(long, default_value = "public")]
access: String,
},
/// Show dependency tree.
Tree {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Maximum depth to display.
#[arg(short, long, default_value_t = 10)]
depth: usize,
/// Show duplicate dependencies.
#[arg(long)]
duplicates: bool,
},
/// Display project information.
Info {
/// Project root directory.
#[arg(default_value = ".")]
root: PathBuf,
/// Output format (text or json).
#[arg(short, long, default_value = "text")]
format: String,
},
}
impl Commands {
/// Execute the command asynchronously.
pub async fn execute(&self) -> Result<()> {
match self {
Commands::Dev { root, port, mock, mock_port, mock_dir } => dev::execute_dev(root, *port, *mock, *mock_port, mock_dir).await,
Commands::Build { root, out_dir } => build::execute_build(root, out_dir).await,
Commands::Compile { root, watch } => build::execute_compile(root, *watch).await,
Commands::Run { task, root, hybrid, watch } => run::execute_run(task, root, *hybrid, *watch).await,
Commands::Git { subcommand } => git::execute_git(subcommand).await,
Commands::Hooks { subcommand } => git::execute_hooks(subcommand).await,
Commands::Serve { root, port, dir } => dev::execute_serve(root, *port, dir).await,
Commands::Bridge { out_dir } => bridge::execute_bridge(out_dir).await,
Commands::Init(args) => init::execute_init(args.clone()).await,
Commands::Test { root, filter, coverage, report, parallel, timeout, watch } => test::execute_test(root, filter.as_ref(), *coverage, *report, *parallel, *timeout, *watch).await,
Commands::Lint { root, report } => test::execute_lint(root, *report).await,
Commands::Format { root, write, report } => test::execute_format(root, *write, *report).await,
Commands::Audit { root, report } => test::execute_audit(root, *report).await,
Commands::Bench { file, iterations } => test::execute_bench(file, *iterations).await,
Commands::Mock { root, port, dir } => dev::execute_mock(root, *port, dir).await,
Commands::Lsp { port, stdio } => lsp::execute_lsp(*port, *stdio).await,
Commands::Mcp { port, stdio } => lsp::execute_mcp(*port, *stdio).await,
Commands::Check { root } => test::execute_check(root).await,
Commands::Add { package, root, dev, optional, features } => package::execute_add(package, root, *dev, *optional, features).await,
Commands::Remove { package, root } => package::execute_remove(package, root).await,
Commands::Update { package, root, latest } => package::execute_update(package, root, *latest).await,
Commands::Install { root, force, production } => package::execute_install(root, *force, *production).await,
Commands::Migrate { root, keep_original } => package::execute_migrate(root, *keep_original).await,
Commands::Clean { root, cache, target } => package::execute_clean(root, *cache, *target).await,
Commands::Search { query, limit } => package::execute_search(query, *limit).await,
Commands::Publish { root, registry, dry_run, access } => package::execute_publish(root, registry, *dry_run, access).await,
Commands::Tree { root, depth, duplicates } => package::execute_tree(root, *depth, *duplicates).await,
Commands::Info { root, format } => package::execute_info(root, format).await,
}
}
}