class
Analyzer::Rust::Cli
- Analyzer::Rust::Cli
- Analyzer
- Reference
- Object
Overview
Surfaces the command-line attack surface of Rust programs as cli://
endpoints: one endpoint per (sub)command with named options
(param_type "flag"), positional arguments ("argument") and consumed
environment variables ("env"). Covers std::env::args/var plus the
clap / structopt / argh derive macros and the getopts builder API
(Options::new() + opts.optopt/optflag/optflagopt/optmulti/reqopt).
Scope notes (follow-ups): the clap builder API (Command::new(...) .arg(Arg::new(...))) is only recognized as a CLI signal, not parsed into
args — a line-scan can't reliably track its method-chain/paren scoping.
Tuple subcommand variants that reference a separate #[derive(Args)]
struct (Serve(ServeArgs)) surface that struct's flags on the root
rather than the subcommand, since the variant→struct link isn't resolved
here; inline-field variants (Serve { ... }) attribute correctly.
Line-scan analyzer (Go/Python CLI house style) with a cross-file URL-merge, instead of the tree-sitter analyze_file path the HTTP Rust analyzers use. Subclasses Analyzer directly (RustEngine#analyze_file is abstract) and reuses RustEngine.test_path? as a class method.
Defined in:
analyzer/analyzers/rust/cli.crConstant Summary
-
ARGH_ATTR_RE =
/#\[\s*argh\s*\(([^\]]*)\)/ -
BUILDER_NEW =
/Command::new\s*\(\s*"([^"]+)"/ -
clap builder marker (used only to recognise a builder-style CLI; the builder arg/subcommand tree is a follow-up — see the note in
#analyze). -
CLAP_ATTR_RE =
/#\[\s*(?:arg|structopt|clap)\s*\(([^\]]*)\)/ -
clap/structopt field attribute, e.g. #[arg(short, long, env = "X")].
-
DERIVE_RE =
/#\[\s*derive\s*\(([^)]*)\)/ -
ENV_ARGS_RE =
/\b(?:std::)?env::args(?:_os)?\s*\(/ -
ENV_VAR_RE =
/\b(?:std::)?env::var(?:_os)?\s*\(\s*"([^"]+)"/ -
builtin.
-
FIELD_RE =
/^\s*(?:pub\s+)?(\w+)\s*:/ -
GETOPTS_CALL_RE =
/\b(\w+)\.(?:optopt|reqopt|optflagopt|optflag|optmulti)\s*\(\s*"([^"]*)"\s*,\s*"([^"]*)"/ -
GETOPTS_NEW_RE =
/\blet\s+(?:mut\s+)?(\w+)(?:\s*:\s*(?:getopts::)?Options)?\s*=\s*(?:getopts::)?Options::new\s*\(\s*\)/ -
getopts: a flat (no-subcommand) builder API.
let mut opts = Options::new();binds a receiver variable, thenopts.optopt(short, long, desc, hint)/optflag(short, long, desc)/optflagopt(short, long, desc, hint)/optmulti(short, long, desc, hint)/reqopt(short, long, desc, hint)register each option on it. The optional type-annotation group tolerates agetopts::prefix (let mut opts: getopts::Options = ...), matching the same prefix already tolerated beforeOptions::new. -
ITEM_RE =
/\b(?:struct|enum)\s+\w+/ -
VARIANT_RE =
/^\s*(?:#\[\s*command\s*\(\s*name\s*=\s*"([^"]+)"[^\]]*\)\s*\]\s*)?([A-Z]\w*)/ -
WEB_CRATE_RE =
/\buse\s+(?:axum|actix_web|rocket|warp|tide|poem|salvo|gotham|loco_rs|hyper|tonic|tower_http)\b|::serve\s*\(|HttpServer::new|TcpListener::bind/ -
Web crates: their env::var reads are config, not a CLI surface.