Skip to main content

meta_ast/interface/
args.rs

1use clap::Parser;
2
3/// Polyglot static analyzer that builds symbol surfaces and cross-file dependency graphs.
4#[derive(Parser)]
5#[command(name = "meta-ast", version, about = "Polyglot static analyzer")]
6pub enum Cli {
7    /// Inspect a project directory/file and extract all symbol definitions
8    ///
9    /// Examples:
10    ///   meta-ast inspect ./my-project
11    ///   meta-ast inspect ./my-project/main.py -f yaml -o symbols.yaml
12    ///   meta-ast inspect ./my-project --language python
13    Inspect(InspectArgs),
14
15    /// Build a cross-file dependency graph and analyze Strongly Connected Components (SCCs)
16    ///
17    /// Examples:
18    ///   meta-ast graph ./my-project
19    ///   meta-ast graph ./my-project --html -o project_graph.html
20    ///   meta-ast graph ./my-project -f yaml -o graph.yaml
21    Graph(GraphArgs),
22
23    /// Scan cross-language call sites and generate MetaCall deployment manifests
24    ///
25    /// Examples:
26    ///   meta-ast deploy ./my-project --out ./deploy-dir
27    ///   meta-ast deploy ./my-project --check
28    #[cfg(feature = "metacall-deploy")]
29    Deploy(DeployArgs),
30}
31
32fn parse_format(s: &str) -> Result<crate::output::OutputFormat, String> {
33    match s.to_lowercase().as_str() {
34        "json" => Ok(crate::output::OutputFormat::Json),
35        "yaml" | "yml" => Ok(crate::output::OutputFormat::Yaml),
36        _ => Err(format!("invalid format '{s}': expected 'json' or 'yaml'")),
37    }
38}
39
40#[derive(Parser)]
41pub struct InspectArgs {
42    /// Root directory or source file to inspect
43    pub path: std::path::PathBuf,
44
45    /// Output file path (prints to stdout if omitted)
46    #[arg(short, long)]
47    pub output: Option<std::path::PathBuf>,
48
49    /// Override automatic language detection and force a specific language
50    #[arg(short, long)]
51    pub language: Option<String>,
52
53    /// Output format for the extracted symbols
54    #[arg(short = 'f', long, default_value = "json", value_parser = parse_format)]
55    pub format: crate::output::OutputFormat,
56}
57
58#[derive(Parser)]
59pub struct GraphArgs {
60    /// Root directory to analyze
61    pub path: std::path::PathBuf,
62
63    /// Output file path (prints to stdout if omitted)
64    #[arg(short, long)]
65    pub output: Option<std::path::PathBuf>,
66
67    /// Override automatic language detection and force a specific language
68    #[arg(short, long)]
69    pub language: Option<String>,
70
71    /// Output serialization format for the graph structure
72    #[arg(short = 'f', long, default_value = "json", value_parser = parse_format)]
73    pub format: crate::output::OutputFormat,
74
75    /// Generate an interactive HTML dashboard with graph visualization
76    #[arg(long)]
77    pub html: bool,
78
79    /// Also emit a portable datagraph.json export (requires --features dataflow)
80    #[cfg(feature = "dataflow")]
81    #[arg(long)]
82    pub datagraph: bool,
83
84    /// Enter watch mode: monitor the project and re-analyze on file changes
85    #[cfg(feature = "watch")]
86    #[arg(long)]
87    pub watch: bool,
88
89    /// Debounce duration in milliseconds for watch mode (default: 200)
90    #[cfg(feature = "watch")]
91    #[arg(long, default_value = "200")]
92    pub watch_debounce: u64,
93}
94
95#[cfg(feature = "metacall-deploy")]
96#[derive(Parser)]
97pub struct DeployArgs {
98    /// Root directory of the project to analyze
99    pub path: std::path::PathBuf,
100
101    /// Output format for generated manifests
102    #[arg(short = 'f', long, default_value = "json", value_parser = parse_format)]
103    pub format: crate::output::OutputFormat,
104
105    /// Check mode: diff generated manifests against existing metacall.json
106    #[arg(long)]
107    pub check: bool,
108
109    /// Output directory for generated manifests and mesh annotation
110    #[arg(short, long, default_value = ".")]
111    pub out: std::path::PathBuf,
112}