MCPcopy Create free account
hub / github.com/Rust-API/Rust-API-Bypass-Checker / main

Function main

src/bin/cargo-api-bypass.rs:143–194  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

141}
142
143fn main() {
144 if let Some(arg1) = std::env::args().nth(1) {
145 let tool_subcommand_mode = Path::new(&arg1)
146 .file_name()
147 .and_then(|n| n.to_str())
148 .map(|file_name| matches!(file_name, "api-bypass" | "bypasser" | "mir-checker"))
149 .unwrap_or(false);
150 let rustc_version_query = std::env::args()
151 .skip(1)
152 .any(|arg| matches!(arg.as_str(), "--version" | "-V" | "-vV"));
153 if !tool_subcommand_mode && rustc_version_query {
154 forward_to_rustc();
155 }
156 }
157
158 // Check for version and help flags even when invoked through the cargo wrapper.
159 if std::env::args().any(|a| a == "--help" || a == "-h") {
160 show_help();
161 return;
162 }
163 if std::env::args().any(|a| a == "--version" || a == "-V") {
164 show_version();
165 return;
166 }
167
168 // 获取第一个参数并解析为路径
169 if let Some(arg1) = std::env::args().nth(1) {
170 let path = Path::new(&arg1);
171 if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) {
172 match file_name {
173 "api-bypass" | "bypasser" | "mir-checker" => {
174 // 当以 `cargo api-bypass` 调用时执行此分支
175 in_cargo_bypasser();
176 }
177 "rustc" => {
178 // 当以 wrapper 方式运行 `cargo rustc`,且 `RUSTC_WRAPPER` 环境变量设置为自身时执行此分支
179 inside_cargo_rustc();
180 }
181 _ => {
182 show_error(format!(
183 "`cargo-api-bypass` must be called with either `api-bypass`/`bypasser` or `rustc` as first argument.",
184 ));
185 }
186 }
187 } else {
188 show_error("无法解析第一个参数的文件名。".to_string());
189 }
190 } else {
191 show_error("缺少必要的命令行参数。".to_string());
192 }
193
194}
195
196// This will construct command line like:
197// `cargo rustc --bin some_crate_name -v -- cargo-api-bypass-marker-begin --top_crate_name some_top_crate_name --domain interval -v cargo-api-bypass-marker-end`

Callers

nothing calls this directly

Calls 6

forward_to_rustcFunction · 0.85
show_helpFunction · 0.85
show_versionFunction · 0.85
in_cargo_bypasserFunction · 0.85
inside_cargo_rustcFunction · 0.85
show_errorFunction · 0.85

Tested by

no test coverage detected