Skip to content

Commit

Permalink
Add support for plaintext output
Browse files Browse the repository at this point in the history
  • Loading branch information
mre committed Dec 16, 2018
1 parent d0ed438 commit 46d96e6
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ license = "Apache-2.0/MIT"
name = "cargo-inspect"
readme = "README.md"
repository = "https://github.com/mre/cargo-inspect"
version = "0.4.0"
version = "0.5.0"

[[bin]]
name = "cargo-inspect"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ USAGE:
FLAGS:
-h, --help Prints help information
--plain Don't highlight output
-V, --version Prints version information
-v, --verbose Print the original code as a comment above the desugared code
Expand Down
4 changes: 4 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ pub struct Config {
/// Print the original code as a comment above the desugared code
#[structopt(short = "v", long = "verbose")]
pub verbose: bool,

/// Don't highlight output
#[structopt(long = "plain")]
pub plain: bool,
}

/// The structopt enum, which serves as an adapter so that the config options
Expand Down
11 changes: 7 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,13 @@ pub fn inspect(config: &Config) -> Result<(), InspectError> {

let formatted = format(hir.output)?;

let printer = PrettyPrinter::default().language("rust").build()?;

let header = config.input.to_owned().unwrap_or(env::current_dir()?);
printer.string_with_header(formatted, header.to_string_lossy().to_string())?;
if config.plain {
println!("{}", formatted);
} else {
let printer = PrettyPrinter::default().language("rust").build()?;
let header = config.input.to_owned().unwrap_or(env::current_dir()?);
printer.string_with_header(formatted, header.to_string_lossy().to_string())?;
}
Ok(())
}

Expand Down

0 comments on commit 46d96e6

Please sign in to comment.