From 551120fba10bbaaa303ea5f745802c92f8df5198 Mon Sep 17 00:00:00 2001 From: Filip Tibell Date: Thu, 24 Apr 2025 22:01:00 +0200 Subject: [PATCH] Pass rest args plainly to process.args when using lune run --- crates/lune/src/cli/mod.rs | 30 ++++++++++++++++++++++++++++-- crates/lune/src/cli/run.rs | 4 ++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/crates/lune/src/cli/mod.rs b/crates/lune/src/cli/mod.rs index 2e050ad..63fad1d 100644 --- a/crates/lune/src/cli/mod.rs +++ b/crates/lune/src/cli/mod.rs @@ -1,4 +1,4 @@ -use std::process::ExitCode; +use std::{env::args_os, process::ExitCode}; use anyhow::Result; use clap::{Parser, Subcommand}; @@ -39,7 +39,33 @@ pub struct Cli { impl Cli { pub fn new() -> Self { - Self::parse() + // TODO: Figure out if there is a better way to do this using clap ... ? + // https://github.com/lune-org/lune/issues/253 + if args_os() + .nth(1) + .is_some_and(|arg| arg.eq_ignore_ascii_case("run")) + { + let Some(script_path) = args_os() + .nth(2) + .and_then(|arg| arg.to_str().map(String::from)) + else { + return Self::parse(); // Will fail and return the help message + }; + + let script_args = args_os() + .skip(3) + .filter_map(|arg| arg.to_str().map(String::from)) + .collect::>(); + + Self { + subcommand: Some(CliSubcommand::Run(RunCommand { + script_path, + script_args, + })), + } + } else { + Self::parse() + } } pub async fn run(self) -> Result { diff --git a/crates/lune/src/cli/run.rs b/crates/lune/src/cli/run.rs index f86f324..eda8cd6 100644 --- a/crates/lune/src/cli/run.rs +++ b/crates/lune/src/cli/run.rs @@ -15,9 +15,9 @@ use super::utils::files::{discover_script_path_including_lune_dirs, strip_sheban #[derive(Debug, Clone, Parser)] pub struct RunCommand { /// Script name or full path to the file to run - script_path: String, + pub(super) script_path: String, /// Arguments to pass to the script, stored in process.args - script_args: Vec, + pub(super) script_args: Vec, } impl RunCommand {