Merge commit '98ed962c7d3eebe12c97588e61245273d265e72f' into master
This commit is contained in:
35
compiler/rustc_codegen_gcc/build_system/src/fmt.rs
Normal file
35
compiler/rustc_codegen_gcc/build_system/src/fmt.rs
Normal file
@@ -0,0 +1,35 @@
|
||||
use crate::utils::run_command_with_output;
|
||||
use std::ffi::OsStr;
|
||||
use std::path::Path;
|
||||
|
||||
fn show_usage() {
|
||||
println!(
|
||||
r#"
|
||||
`fmt` command help:
|
||||
|
||||
--check : Pass `--check` argument to `cargo fmt` commands
|
||||
--help : Show this help"#
|
||||
);
|
||||
}
|
||||
|
||||
pub fn run() -> Result<(), String> {
|
||||
let mut check = false;
|
||||
// We skip binary name and the `info` command.
|
||||
let mut args = std::env::args().skip(2);
|
||||
while let Some(arg) = args.next() {
|
||||
match arg.as_str() {
|
||||
"--help" => {
|
||||
show_usage();
|
||||
return Ok(());
|
||||
}
|
||||
"--check" => check = true,
|
||||
_ => return Err(format!("Unknown option {}", arg)),
|
||||
}
|
||||
}
|
||||
|
||||
let cmd: &[&dyn AsRef<OsStr>] =
|
||||
if check { &[&"cargo", &"fmt", &"--check"] } else { &[&"cargo", &"fmt"] };
|
||||
|
||||
run_command_with_output(cmd, Some(&Path::new(".")))?;
|
||||
run_command_with_output(cmd, Some(&Path::new("build_system")))
|
||||
}
|
||||
Reference in New Issue
Block a user