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
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Debug, Parser)]
#[command(
name = "morph",
version,
about = "Plugin-based code transformation CLI for migrating codebases",
long_about = None,
after_help = "✨ GETTING STARTED WITH morph-cli ✨\n\n\
1. Scan your project to identify files & technologies:\n\
$ morph scan\n\n\
2. Plan recommendations & estimate maturity/confidence:\n\
$ morph plan\n\n\
3. Run the interactive guided assistant wizard:\n\
$ morph magic\n\n\
🚀 BEGINNER-SAFE RECOMMENDATIONS:\n\n\
• Migrate legacy CommonJS require calls to modern ESM imports:\n\
$ morph run commonjs-to-esm . --dry-run --review\n\n\
• Safely upgrade JavaScript files to TypeScript with complete confidence:\n\
$ morph run js-to-ts . --dry-run --review\n\n\
• Validate repository setup and environment health:\n\
$ morph doctor .\n\n\
👉 Need help? Visit our docs or run a preset workflow: `morph preset list`"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
/// Print the current morph-cli version
Version,
/// List available migration recipes
List {
#[arg(default_value = ".")]
path: PathBuf,
/// Filter recipes by category (e.g. migration, cleanup, modernization, analysis, experimental)
#[arg(long)]
category: Option<String>,
/// Filter recipes by tag (e.g. safe, fast, risky, typescript, react, backend, frontend)
#[arg(long)]
tag: Option<String>,
},
/// Search for recipes matching a query
Search {
/// Search query (matches name, description, category, tags)
query: String,
#[arg(default_value = ".")]
path: PathBuf,
/// Filter by category (e.g. migration, cleanup, modernization, analysis, experimental)
#[arg(long)]
category: Option<String>,
/// Filter by maturity (e.g. stable, beta, experimental)
#[arg(long)]
maturity: Option<String>,
},
/// Show migration history summaries
History {
/// Limit the number of sessions to display
#[arg(short = 'n', long, default_value_t = 10)]
limit: usize,
},
/// Initialize a new morph-cli.toml configuration file
Init {
#[arg(default_value = ".")]
path: PathBuf,
},
/// Plan recommended migration recipes for a project
#[command(visible_alias = "p")]
Plan {
#[arg(default_value = ".")]
path: PathBuf,
/// Filter by file tag (e.g. commonjs, esm, react, typescript, risky, generated, ignored)
#[arg(long)]
tag: Option<String>,
},
/// Explain migration detection for a file
Explain { file: PathBuf },
/// Run a recipe against a target path
Run {
#[arg(required = true, num_args = 2.., value_name = "RECIPE... PATH")]
args: Vec<String>,
#[arg(long)]
write: bool,
#[arg(long)]
dry_run: bool,
#[arg(long)]
review: bool,
#[arg(long)]
autofix: bool,
#[arg(long)]
verbose: bool,
#[arg(long)]
summary_only: bool,
#[arg(long)]
max_preview_lines: Option<usize>,
#[arg(long)]
allow_risky: bool,
#[arg(long)]
strict: bool,
/// Generate JSON report
#[arg(long)]
report_json: bool,
/// Generate Markdown report
#[arg(long)]
report_md: bool,
/// Output directory for reports
#[arg(long, default_value = ".morph-cli/reports")]
report_dir: PathBuf,
/// Enable formatting preservation
#[arg(long)]
format: bool,
/// Use Prettier for formatting
#[arg(long)]
prettier: bool,
/// Disable formatting
#[arg(long)]
no_format: bool,
/// Number of parallel jobs (default: CPU count)
#[arg(long)]
jobs: Option<usize>,
/// Run sequentially (disable parallelism)
#[arg(long)]
sequential: bool,
/// Limit execution to a workspace package by package name
#[arg(long)]
package: Option<String>,
/// Profile name to load config overrides from
#[arg(long)]
profile: Option<String>,
/// Output style (minimal, default, detailed)
#[arg(long)]
output_style: Option<String>,
/// Filter by file tag (e.g. commonjs, esm, react, typescript, risky, generated, ignored)
#[arg(long)]
tag: Option<String>,
},
/// List migration run sessions
Sessions,
/// Show a migration run session
Session { id: String },
/// Rollback files from a previous transformation session
Rollback {
session_id: String,
#[arg(long)]
preview: bool,
#[arg(long)]
force: bool,
},
/// Replay a previous transformation session with stored options
Replay {
session_id: String,
/// Apply changes (write to disk), overrides stored mode if true
#[arg(long)]
write: bool,
},
/// Resume migration from a saved checkpoint
Resume {
/// Checkpoint ID to resume from
#[arg(long)]
checkpoint: String,
},
/// List scan snapshots
Scans,
/// Generate shell completion scripts
Completions {
/// The shell to generate completions for
#[arg(value_enum)]
shell: clap_complete::Shell,
},
/// Scan project and detect technologies
#[command(visible_alias = "s")]
Scan {
#[command(subcommand)]
action: Option<ScanAction>,
#[arg(default_value = ".")]
path: PathBuf,
/// Filter by file tag (e.g. commonjs, esm, react, typescript, risky, generated, ignored)
#[arg(long)]
tag: Option<String>,
/// Show verbose skip output
#[arg(short = 'v', long)]
verbose: bool,
},
/// Analyze lightweight dependencies
Deps {
#[arg(default_value = ".")]
path: PathBuf,
},
/// Calculate modernization score and readiness
Score {
#[arg(default_value = ".")]
path: PathBuf,
/// Output format (text or json)
#[arg(long, default_value = "text")]
format: String,
},
/// Simulate migration impact without transforming files
#[command(visible_alias = "sim")]
Simulate {
/// Recipes to simulate; repeat to select multiple recipes
#[arg(short = 'r', long = "recipe", required = true)]
recipes: Vec<String>,
#[arg(default_value = ".")]
path: PathBuf,
},
/// Start the local dashboard backend
Dashboard {
/// Port to listen on (default: 8080)
#[arg(long, default_value_t = 8080)]
port: u16,
},
/// Start a guided migration workflow
Magic {
#[arg(default_value = ".")]
path: PathBuf,
},
/// Run a full validation suite on a repository (scan, detect, dry-run, verify)
#[command(visible_alias = "validate")]
ValidateRepo {
#[arg(default_value = ".")]
path: PathBuf,
},
/// Benchmark Morph execution performance on the target path
#[command(visible_alias = "bench")]
Benchmark {
#[arg(default_value = ".")]
path: PathBuf,
},
/// Generate visualization graphs (Mermaid or JSON)
Graph {
/// Type of graph to generate (pipeline, workspace, deps)
#[arg(long, default_value = "pipeline")]
graph_type: String,
/// Output format (mermaid or json)
#[arg(long, default_value = "mermaid")]
format: String,
#[arg(default_value = ".")]
path: PathBuf,
},
/// Manage preset workflows
Preset {
#[command(subcommand)]
action: PresetAction,
},
/// Verify the integrity of transformed files (syntax, imports, exports)
Verify {
#[arg(default_value = ".")]
path: PathBuf,
},
/// Watch for file changes and re-run migration analysis
Watch {
#[arg(default_value = ".")]
path: PathBuf,
/// Recipe to analyze; repeat to select multiple recipes
#[arg(long = "recipe")]
recipes: Vec<String>,
/// Debounce delay in milliseconds
#[arg(long, default_value_t = 500)]
debounce_ms: u64,
},
/// AI-powered suggestions and analysis
Ai {
#[command(subcommand)]
action: AiAction,
},
/// Manage and run migration manifests
Manifest {
#[command(subcommand)]
action: ManifestAction,
},
/// Manage plugins
Plugins {
#[command(subcommand)]
action: PluginAction,
},
/// View ignored and skipped files with reasons
Ignored {
#[arg(default_value = ".")]
path: PathBuf,
/// Show detailed list of all ignored files instead of a summary
#[arg(short, long)]
detailed: bool,
},
/// List all dry-run execution snapshots
DryRuns,
/// View detailed metrics of a specific dry-run execution snapshot
DryRun {
#[command(subcommand)]
action: DryRunAction,
},
/// Generate markdown documentation for Morph CLI components
Docs,
/// Check repository health and environment
Doctor {
#[arg(default_value = ".")]
path: PathBuf,
},
}
#[derive(Debug, Subcommand)]
pub enum AiAction {
/// Suggest improvements for a specific file
Suggest { file: PathBuf },
}
#[derive(Debug, Subcommand)]
pub enum PresetAction {
/// List all built-in presets
List,
/// Run a specific preset workflow
Run {
/// Name of the preset to run
name: String,
/// Target path (defaults to current directory)
#[arg(default_value = ".")]
path: PathBuf,
/// Apply changes (write to disk)
#[arg(long)]
write: bool,
},
}
#[derive(Debug, Subcommand)]
pub enum PluginAction {
/// List all discovered plugins
List,
/// Show detailed info about a plugin
Info { name: String },
}
#[derive(Debug, Subcommand, Clone)]
pub enum ManifestAction {
/// Create a migration manifest file
Create {
/// Path to save the manifest (e.g. morph-migration.toml)
#[arg(default_value = "morph-migration.toml")]
file: std::path::PathBuf,
/// Optional configuration profile to use
#[arg(long)]
profile: Option<String>,
/// Recipes to execute; repeat to specify multiple recipes
#[arg(short = 'r', long = "recipe")]
recipes: Vec<String>,
/// Target path to apply migration to (defaults to current directory)
#[arg(short = 't', long = "target", default_value = ".")]
target: std::path::PathBuf,
/// Apply changes (write to disk)
#[arg(long)]
write: bool,
/// Simulate execution without writing to disk
#[arg(long)]
dry_run: bool,
/// Allow recipes to execute even with potential risks
#[arg(long)]
allow_risky: bool,
/// Enforce strict type checking and zero warnings
#[arg(long)]
strict: bool,
/// Automatically fix minor lint/style issues
#[arg(long)]
autofix: bool,
},
/// Run a migration manifest file
Run {
/// Path to the manifest file (e.g. morph-migration.toml)
file: std::path::PathBuf,
},
}
#[derive(Debug, Subcommand, Clone)]
pub enum DryRunAction {
/// Show a specific dry-run execution snapshot by ID
Show { id: String },
}
#[derive(Debug, Subcommand, Clone)]
pub enum ScanAction {
/// Show a specific scan snapshot by ID
Show { id: String },
}
pub fn parse() -> Cli {
Cli::parse()
}