Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geocode: when producing JSON output with the now subcommands, use c… #1345

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/cmd/geocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,18 @@ async fn geocode_main(args: Args) -> CliResult<()> {
let engine = load_engine(geocode_index_file.clone().into(), &progress).await?;

let mut rdr = rconfig.reader()?;
let mut wtr = Config::new(&args.flag_output).writer()?;
let mut wtr = Config::new(&args.flag_output)
.quote_style(
// if we're doing a now subcommand with JSON output, we don't want the CSV writer
// to close quote the output as it will produce invalid JSON
if now_cmd && (args.flag_formatstr == "%json" || args.flag_formatstr == "%pretty-json")
{
csv::QuoteStyle::Never
} else {
csv::QuoteStyle::Necessary
},
)
.writer()?;

let headers = rdr.byte_headers()?.clone();
let sel = rconfig.selection(&headers)?;
Expand Down
8 changes: 3 additions & 5 deletions tests/test_geocode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1564,9 +1564,8 @@ fn geocode_countryinfonow_formatstr_pretty_json() {
.arg("mx")
.args(["--formatstr", "%pretty-json"]);

let got: Vec<Vec<String>> = wrk.read_stdout(&mut cmd);
let expected = vec![svec![
r######"{
let got: String = wrk.stdout(&mut cmd);
let expected = r######"{
"info": {
"iso": "MX",
"iso3": "MEX",
Expand Down Expand Up @@ -1594,7 +1593,6 @@ fn geocode_countryinfonow_formatstr_pretty_json() {
"capital_names": {
"en": "Mexico City"
}
}"######
]];
}"######;
assert_eq!(got, expected);
}
Loading