Pass rest args plainly to process.args when using lune run

This commit is contained in:
Filip Tibell 2025-04-24 22:01:00 +02:00
parent 88494fedcb
commit 551120fba1
No known key found for this signature in database
2 changed files with 30 additions and 4 deletions

View file

@ -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::<Vec<_>>();
Self {
subcommand: Some(CliSubcommand::Run(RunCommand {
script_path,
script_args,
})),
}
} else {
Self::parse()
}
}
pub async fn run(self) -> Result<ExitCode> {

View file

@ -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<String>,
pub(super) script_args: Vec<String>,
}
impl RunCommand {