From 9c8284cd0626ccdcdba709f6ade4faa604fd0f79 Mon Sep 17 00:00:00 2001 From: Cole Helbling Date: Tue, 28 Feb 2023 08:38:42 -0800 Subject: [PATCH] Add newline to end of plan json output (#283) * 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 --- src/cli/subcommand/plan.rs | 2 +- src/plan.rs | 2 +- tests/fixtures/linux/linux.json | 2 +- tests/fixtures/linux/steam-deck.json | 2 +- tests/fixtures/macos/macos.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cli/subcommand/plan.rs b/src/cli/subcommand/plan.rs index 5a51944..a1d4877 100644 --- a/src/cli/subcommand/plan.rs +++ b/src/cli/subcommand/plan.rs @@ -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")?; diff --git a/src/plan.rs b/src/plan.rs index ca5ed3b..d144835 100644 --- a/src/plan.rs +++ b/src/plan.rs @@ -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(()) diff --git a/tests/fixtures/linux/linux.json b/tests/fixtures/linux/linux.json index f136bb3..dcc5a7c 100644 --- a/tests/fixtures/linux/linux.json +++ b/tests/fixtures/linux/linux.json @@ -915,4 +915,4 @@ "start_daemon": true } } -} \ No newline at end of file +} diff --git a/tests/fixtures/linux/steam-deck.json b/tests/fixtures/linux/steam-deck.json index 862f1f8..9805009 100644 --- a/tests/fixtures/linux/steam-deck.json +++ b/tests/fixtures/linux/steam-deck.json @@ -937,4 +937,4 @@ "start_daemon": true } } -} \ No newline at end of file +} diff --git a/tests/fixtures/macos/macos.json b/tests/fixtures/macos/macos.json index f6ea546..5200f39 100644 --- a/tests/fixtures/macos/macos.json +++ b/tests/fixtures/macos/macos.json @@ -969,4 +969,4 @@ "volume_label": "Nix Store", "root_disk": "disk3" } -} \ No newline at end of file +}