Skip to content

Commit

Permalink
Allow reading input from stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
vlinkz committed Sep 15, 2022
1 parent 651e2a3 commit 188f6f8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{self, ArgGroup, Parser};
use nix_editor::{write::deref, write::write, write::addtoarr};
use std::{fs, path::Path, io::Write};
use std::{fs, io::Write};
use owo_colors::*;

#[derive(Parser)]
Expand Down Expand Up @@ -126,11 +126,13 @@ fn printerror(msg: &str) {
fn main() {
let args = Args::parse();
let output;
if !Path::is_file(Path::new(&args.file)) {
nofileerr(&args.file);
std::process::exit(1);
}
let f = fs::read_to_string(&args.file).expect("Failed to read file");
let f = match fs::read_to_string(&args.file) {
Ok(x) => x,
Err(_) => {
nofileerr(&args.file);
std::process::exit(1);
}
};

if args.arr.is_some() {
output = match addtoarr(&f, &args.attribute, vec![args.arr.unwrap()]) {
Expand Down

0 comments on commit 188f6f8

Please sign in to comment.