Skip to content

Commit

Permalink
Add newline to end of plan json output (#283)
Browse files Browse the repository at this point in the history
* Add newline to end of `plan` json output

This causes some shells (like sh) to continue their prompt right after
the closing brace, which is kinda meh.

* Add newline to end of `receipt.json`

`cat /nix/receipt.json` has the same issue as the previous commit, in
that it will bleed into the prompt for some shells that don't insert an
implicit newline.

* Add newline to end of fixture json documents
  • Loading branch information
cole-h authored Feb 28, 2023
1 parent d49e12c commit 9c8284c
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/cli/subcommand/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl CommandExecute for Plan {
};

let json = serde_json::to_string_pretty(&install_plan)?;
tokio::fs::write(output, json)
tokio::fs::write(output, format!("{json}\n"))
.await
.wrap_err("Writing plan")?;

Expand Down
2 changes: 1 addition & 1 deletion src/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ async fn write_receipt(plan: InstallPlan) -> Result<(), NixInstallerError> {
let install_receipt_path = PathBuf::from(RECEIPT_LOCATION);
let self_json =
serde_json::to_string_pretty(&plan).map_err(NixInstallerError::SerializingReceipt)?;
tokio::fs::write(&install_receipt_path, self_json)
tokio::fs::write(&install_receipt_path, format!("{self_json}\n"))
.await
.map_err(|e| NixInstallerError::RecordingReceipt(install_receipt_path, e))?;
Result::<(), NixInstallerError>::Ok(())
Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/linux/linux.json
Original file line number Diff line number Diff line change
Expand Up @@ -915,4 +915,4 @@
"start_daemon": true
}
}
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/linux/steam-deck.json
Original file line number Diff line number Diff line change
Expand Up @@ -937,4 +937,4 @@
"start_daemon": true
}
}
}
}
2 changes: 1 addition & 1 deletion tests/fixtures/macos/macos.json
Original file line number Diff line number Diff line change
Expand Up @@ -969,4 +969,4 @@
"volume_label": "Nix Store",
"root_disk": "disk3"
}
}
}

0 comments on commit 9c8284c

Please sign in to comment.