Skip to content

Commit

Permalink
fix(fix-cmd): should check if the input pipe is activated
Browse files Browse the repository at this point in the history
  • Loading branch information
Joxit committed Sep 29, 2023
1 parent 5bb1161 commit db79e1c
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions src/commands/fix.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
use crate::commands::export::Export;
use crate::fix::Fix;
use crate::repo::Walk;
use crate::utils::ResultExit;
use log::error;
use std::io::{Read, Write};
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
pub struct FixCommand {}
pub struct FixCommand {
/// Paths to WOF documents.
#[structopt(default_value = ".")]
pub directories: Vec<String>,
}

impl FixCommand {
pub fn exec(&self) {
crate::utils::logger::set_verbose(false, "wof::fix").expect_exit("Can't init logger.");
let fix = Fix::new();
loop {
let mut input = String::new();
match std::io::stdin().read_line(&mut input) {
Ok(0) => break,
Ok(_) => {
input = input.trim().to_string();
if input.is_empty() {
continue;
if crate::commands::input_pipe() {
loop {
let mut input = String::new();
match std::io::stdin().read_line(&mut input) {
Ok(0) => break,
Ok(_) => {
input = input.trim().to_string();
if input.is_empty() {
continue;
}
let mut json_value =
crate::parse_string_to_json(&input).expect_exit("Malformed json object");
fix.fix(&mut json_value);
crate::json_to_writer(&json_value, &mut std::io::stdout()).exit_silently();
println!();
}
let mut json_value =
crate::parse_string_to_json(&input).expect_exit("Malformed json object");
fix.fix(&mut json_value);
crate::json_to_writer(&json_value, &mut std::io::stdout()).exit_silently();
writeln!(std::io::stdout(), "").exit_silently();
Err(_) => break,
}
Err(_) => break,
}
}
}
Expand Down

0 comments on commit db79e1c

Please sign in to comment.