forked from antoyo/rustc_codegen_gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rust-lang#510 from GuillaumeGomez/fmt-cmd
Add `fmt` command
- Loading branch information
Showing
3 changed files
with
42 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"))) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters