Skip to content

Commit

Permalink
Merge pull request #4 from eza-community/cafk-gen_binary
Browse files Browse the repository at this point in the history
Introduce `gen_binary` field
  • Loading branch information
cafkafk authored Sep 22, 2023
2 parents 1f44284 + 082e834 commit 1e7dac4
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ pub mod utils {
use std::process::{Command, Output};

pub fn get_help(command: &str, _args: &[&str]) -> Result<Vec<u8>, std::io::Error> {
// TODO: parse args
// let output: Output = Command::new(command).args(args).output()?;
let output: Output = Command::new(command).args(["--help"]).output()?;

if !output.status.success() {
Expand Down Expand Up @@ -90,11 +88,20 @@ fn main() -> std::io::Result<()> {

let parse: Vec<(Option<String>, Option<String>)>;

// This decided what binary to use:
// 1. If user provided `run` flag, we use what they provide
// 2. Else if the config has a `gen_binaries` record, we use that
// 3. Else, we use stdin
if let Some(run) = matches.get_one::<String>("run") {
parse = match crate::utils::get_help(run, &[]) {
Ok(parse) => crate::parser::parse(BufReader::new(parse.as_slice())),
Err(e) => panic!("{:?}", e),
};
} else if let Some(run) = config.gen_binary {
parse = match crate::utils::get_help(&run, &[]) {
Ok(parse) => crate::parser::parse(BufReader::new(parse.as_slice())),
Err(e) => panic!("{:?}", e),
}
} else {
parse = crate::parser::parse(std::io::stdin().lock());
}
Expand Down

0 comments on commit 1e7dac4

Please sign in to comment.