Skip to content

Commit

Permalink
pretty print
Browse files Browse the repository at this point in the history
Summary: pretty printing result

Reviewed By: alanz

Differential Revision: D55311176

fbshipit-source-id: 99c673d146295f7619db93663b446af377bbae90
  • Loading branch information
perehonchuk authored and facebook-github-bot committed Apr 5, 2024
1 parent 8b48cfd commit c544d0c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 2 additions & 0 deletions crates/elp/src/bin/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ pub struct Glean {
pub to: Option<PathBuf>,
/// Produce glean db with macros, types, xrefs. Incompatible with previous
pub v2: bool,
/// Pretty print
pub pretty: bool,
}

#[derive(Clone, Debug)]
Expand Down
17 changes: 13 additions & 4 deletions crates/elp/src/bin/glean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,20 @@ pub fn index(args: &Glean, cli: &mut dyn Cli) -> Result<()> {
} else {
facts.to_v1_facts()
};
write_results(facts, cli, &args.to)
write_results(facts, cli, &args.to, args.pretty)
}

fn write_results(facts: Vec<Fact>, cli: &mut dyn Cli, to: &Option<PathBuf>) -> Result<()> {
let content = serde_json::to_string(&facts)?;
fn write_results(
facts: Vec<Fact>,
cli: &mut dyn Cli,
to: &Option<PathBuf>,
pretty: bool,
) -> Result<()> {
let content = if pretty {
serde_json::to_string_pretty(&facts)?
} else {
serde_json::to_string(&facts)?
};
match to {
Some(to) => std::fs::OpenOptions::new()
.write(true)
Expand Down Expand Up @@ -1288,7 +1297,7 @@ mod tests {
xref_v2: vec![],
};

write_results(facts.to_v1_facts(), &mut cli, &None).expect("success");
write_results(facts.to_v1_facts(), &mut cli, &None, false).expect("success");

let (out, err) = cli.to_strings();
let expected = expect_file!["../resources/test/glean/serialization_test.out"];
Expand Down
3 changes: 2 additions & 1 deletion crates/elp/src/resources/test/glean_help.stdout
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Usage: [--project PROJECT] [--module MODULE] [--to TO] [--v2]
Usage: [--project PROJECT] [--module MODULE] [--to TO] [--v2] [--pretty]

Available options:
--project <PROJECT> Path to directory with project, or to a JSON file (defaults to `.`)
--module <MODULE>
--to <TO> Path to a directory where to dump result
--v2 Produce glean db with macros, types, xrefs. Incompatible with previous
--pretty Pretty print
-h, --help Prints help information

0 comments on commit c544d0c

Please sign in to comment.