From 424c47d327f39071263bc2a45c01211a6f6dab18 Mon Sep 17 00:00:00 2001 From: Austen Adler Date: Tue, 3 Sep 2024 23:34:34 -0400 Subject: [PATCH] Fix multiple bugs --- src/main.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6431f70..ad797ae 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,10 +5,11 @@ use crossbeam_channel::{Receiver, Sender}; use notify_debouncer_mini::{new_debouncer, notify::*, DebounceEventResult}; use std::{ collections::HashSet, - ffi::OsString, + ffi::{OsStr, OsString}, fs, io::Write, path::{Path, PathBuf}, + str::FromStr, time::Duration, }; @@ -71,7 +72,11 @@ impl FmtArgs { "Argument parsing error -- input was empty, but --inplace was specified", ))) } else if let Some(ref output_file) = &self.output { - Some(JsoncOutput::File(output_file)) + Some(if output_file.as_os_str() == "-" { + JsoncOutput::Stdout + } else { + JsoncOutput::File(output_file) + }) } else if self.json_output.is_some() { // We don't want to output jsonc anywhere if they don't specify -o and they do specify -O None @@ -139,9 +144,9 @@ fn format_single_file( // Format json next if let Some(ref json_output_file) = json_output { let output = if json_compact { - fjson::to_json(&input_str).context("Formatting to json") - } else { fjson::to_json_compact(&input_str).context("Formatting to json") + } else { + fjson::to_json(&input_str).context("Formatting to json") }?; if json_output_file.as_ref().as_os_str() == "-" {