class
Analyzer::Zig::Cli
- Analyzer::Zig::Cli
- Analyzer
- Reference
- Object
Overview
Surfaces the command-line attack surface of Zig programs as cli://
endpoints: zig-clap param strings, zig-cli literals, zig-args struct
fields, yazap App/Arg builder calls, plus std.process argv / env reads.
Line-scan, merged by URL.
Included Modules
Defined in:
analyzer/analyzers/zig/cli.crConstant Summary
-
ARGS_FIELD_RE =
/^\s*([A-Za-z_]\w*)\s*:/ -
ARGS_IDX =
/\bargs\s*\[\s*(\d+)\s*\]/ -
builtin.
-
ARGS_IMPORT_ALIAS_RE =
/\b(?:pub\s+)?const\s+(\w+)\s*=\s*@import\s*\(\s*"args"\s*\)/ -
zig-args:
argsParser.parseForCurrentProcess(Options, allocator, .print)/argsParser.parse(Options, &iterator, allocator, .print). The receiver MUST be the local alias bound to@import("args")(captured via ARGS_IMPORT_ALIAS_RE below) -- otherwise an unrelated.parse(...)call on some other receiver (e.g. a URI parser also exposing aparsemethod) could be mistaken for the CLI's option struct. The type name is resolved to itsconst <Name> = struct { ... };declaration (or, for an inline anonymous struct literal, the call site itself) and every top-level field becomes a flag. -
ARGS_IMPORT_RE =
/@import\s*\(\s*"args"\s*\)/ -
CLAP_ARG =
/\\\\\s*<([A-Za-z_]\w*)>/ -
CLAP_FLAG =
/\\\\\s*(?:-[A-Za-z0-9]\s*,\s*)?--([A-Za-z0-9][\w-]*)/ -
zig-clap multiline param string lines (each begins with
\\). -
CLI_LONG =
/\.long_name\s*=\s*"(-{0,2}[A-Za-z0-9][\w-]*)"/ -
zig-cli struct literals. (Only flags are extracted: a
.nameliteral is ambiguous between the app name, a subcommand, and a positional-arg name, so subcommand extraction from zig-cli is a follow-up.) -
GET_ENV =
/\b(?:std\.process\.getEnvVarOwned\s*\(\s*[\w.]+\s*,\s*"([^"]+)"|(?:std\.)?posix\.getenv\s*\(\s*"([^"]+)")/ -
MARKERS =
/@import\s*\(\s*"cli"\s*\)|@import\s*\(\s*"clap"\s*\)|@import\s*\(\s*"args"\s*\)|@import\s*\(\s*"yazap"\s*\)|\b(?:std\.)?process\.argsAlloc\s*\(|\bclap\.(?:parseParamsComptime|parse)\b|\bcli\.(?:Command|App|Runner)\b/ -
STRONG_MARKERS =
/@import\s*\(\s*"cli"\s*\)|@import\s*\(\s*"clap"\s*\)|\b(?:std\.)?process\.argsAlloc\s*\(|\bclap\.(?:parseParamsComptime|parse)\b|\bcli\.(?:Command|App|Runner)\b/ -
The subset of MARKERS that is either library-specific API usage or a bare import that pre-dates this file's zig-args/yazap support (kept as-is: an established, non-regressed convention elsewhere in this analyzer). A file matching only via a bare
@import("args")or@import("yazap")-- with no corresponding API call anywhere in the file -- is NOT proof of a CLI surface (a project can vendor an unrelated module that happens to be named "args"), so it must not seed a zero-evidencecli://<binary>root endpoint. yazap doesn't need a separate evidence constant here: its bare@import("yazap")alone never seeds an endpoint either, because YAZAP_ROOT_RE / YAZAP_SUBCMD_RE / YAZAP_ADD_ARG_RE (used later, in the same forward pass) only call fetch_endpoint when they find a genuine rootCommand/createCommand/addArg call -- so an import with no real yazap usage naturally yields zero endpoints once the root pre-seed below is gated on STRONG_MARKERS. -
WEB_RE =
/@import\s*\(\s*"(?:zap|jetzig|httpz|tokamak)"\s*\)/ -
YAZAP_ADD_ARG_RE =
/(\w+)\.addArg\s*\(\s*Arg\.(positional|booleanOption|singleValueOption)\s*\(\s*"([^"]+)"/ -
YAZAP_ROOT_RE =
/(\w+)\s*=\s*\w+\.rootCommand\s*\(\s*\)/ -
yazap:
App.init(...),app.rootCommand(),app.createCommand("name", ...)and<receiver>.addArg(Arg.positional/booleanOption/singleValueOption(...)). Receiver variables are mapped to their command URL incrementally, in the SAME forward pass as the addArg scan (see#analyzebelow), so a variable reused across subcommands (e.g. a genericcmd) resolves to whichever command was assigned to it as of that line, never a whole-file map where a later reassignment retroactively overwrites an earlier addArg's receiver. -
YAZAP_SUBCMD_RE =
/(\w+)\s*=\s*\w+\.createCommand\s*\(\s*"([^"]+)"/
Class Method Summary
Instance Method Summary
- #analyze
-
#tech : String
Instance-side view of the same declaration.
Instance methods inherited from class Analyzer
analyze
analyze,
base_path : String
base_path,
base_paths : Array(String)
base_paths,
base_relative_path(path : String) : String
base_relative_path,
callees_needed? : Bool
callees_needed?,
content_matches?(content : String, markers : Regex) : Bool
content_matches?,
http_header_name(name : String) : String | Nil
http_header_name,
line_number_for_index(content : String, char_index : Int32) : Int32
line_number_for_index,
logger : NoirLogger
logger,
parallel_analyze(files : Array(String), &block : String -> Nil)
parallel_analyze,
read_file_content(path : String) : String
read_file_content,
result : Array(Endpoint)
result,
tech : String
tech,
unique_params(params : Array(Param)) : Array(Param)
unique_params,
url : String
url,
web_root_path(path : String, markers : Array(String)) : String
web_root_path
Constructor methods inherited from class Analyzer
new(options : Hash(String, YAML::Any))
new
Macros inherited from class Analyzer
analyzer_for(tech)
analyzer_for
Instance methods inherited from module FileHelper
all_files : Array(String)
all_files,
get_files_by_basename(basename : String) : Array(String)
get_files_by_basename,
get_files_by_extension(extension : String) : Array(String)
get_files_by_extension,
get_files_by_extensions(extensions : Array(String)) : Array(String)
get_files_by_extensions,
get_files_by_prefix(prefix : String) : Array(String)
get_files_by_prefix,
get_files_by_prefix_and_extension(prefix : String, extension : String) : Array(String)
get_files_by_prefix_and_extension,
get_files_by_relative_path(relative_path : String, root : String = "") : Array(String)
get_files_by_relative_path,
get_public_dir_files(base_path : String, folder : String) : Array(String)
get_public_dir_files,
get_public_files(base_path : String, anchors : Array(String) = ["shard.yml", "Gemfile"]) : Array(String)
get_public_files,
walked_path(expanded : String) : String
walked_path
Class Method Detail
Instance Method Detail
Instance-side view of the same declaration. The per-file rescues live on
this base class, which has no way to name the analyzer that is running
inside them, so a skipped file could not be attributed to a tech.
Deriving it from analyzer_for keeps the name written exactly once.