Skip to content

Commit

Permalink
feat(cli): allow stdin input as args
Browse files Browse the repository at this point in the history
  • Loading branch information
QaidVoid committed Nov 12, 2024
1 parent e47083d commit 5e1fcaf
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use core::{
log::setup_logging,
util::{cleanup, print_env, setup_required_paths},
};
use std::{env, path::Path};
use std::{env, io::Read, path::Path};

mod cli;
pub mod core;
Expand All @@ -21,7 +21,21 @@ mod package;
mod registry;

async fn handle_cli() -> Result<()> {
let args = Args::parse();
let mut args = env::args().collect::<Vec<_>>();

if let Some(command) = args.last() {
if command == "-" {
args.pop();
let mut stdin = std::io::stdin();
let mut buffer = String::new();
if stdin.read_to_string(&mut buffer).is_ok() {
let stdin_args = buffer.split_whitespace().collect::<Vec<&str>>();
args.extend(stdin_args.into_iter().map(String::from));
}
}
}

let args = Args::try_parse_from(args)?;

setup_logging(&args);

Expand Down
2 changes: 1 addition & 1 deletion src/misc/download.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ pub async fn download_and_save(
}
);

let asset_idx = select_asset_idx(&assets, releases.len())?;
let asset_idx = select_asset_idx(&assets, assets.len())?;
assets[asset_idx]
}
}
Expand Down

0 comments on commit 5e1fcaf

Please sign in to comment.