filter out subcommand from args

This commit is contained in:
Tareq Imbasher 2025-04-13 05:56:50 +03:00
parent 64fe276d0b
commit 41c6f66310
2 changed files with 15 additions and 2 deletions

View File

@ -8,7 +8,7 @@ fn get_current_dir() -> Option<PathBuf> {
}
#[derive(Parser, Debug)]
#[command(author, version = version(), about)]
#[command(bin_name = "crate-seek", author, version = version(), about)]
pub struct Cli {
/// Specifies the root or subdirectory of a Cargo project
#[arg(default_value=get_current_dir().unwrap_or_default().into_os_string())]

View File

@ -20,7 +20,8 @@ async fn main() -> color_eyre::Result<()> {
errors::init()?;
logging::init()?;
let args = Cli::parse();
let args = filter_subcommand(std::env::args().collect());
let args = Cli::parse_from(args);
let mut app = App::new(
args.tick_rate,
args.frame_rate,
@ -31,3 +32,15 @@ async fn main() -> color_eyre::Result<()> {
app.run().await?;
Ok(())
}
fn filter_subcommand(args: Vec<String>) -> Vec<String> {
// Check if the binary was invoked as a Cargo subcommand
if args.get(1).map(String::as_str) == Some("seek") {
// Skip the seek subcommand
std::iter::once(args[0].clone())
.chain(args.into_iter().skip(2))
.collect()
} else {
args
}
}