mirror of
https://github.com/lune-org/lune.git
synced 2025-05-04 10:43:57 +01:00
Pass rest args plainly to process.args when using lune run
This commit is contained in:
parent
88494fedcb
commit
551120fba1
2 changed files with 30 additions and 4 deletions
|
@ -1,4 +1,4 @@
|
||||||
use std::process::ExitCode;
|
use std::{env::args_os, process::ExitCode};
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use clap::{Parser, Subcommand};
|
use clap::{Parser, Subcommand};
|
||||||
|
@ -39,7 +39,33 @@ pub struct Cli {
|
||||||
|
|
||||||
impl Cli {
|
impl Cli {
|
||||||
pub fn new() -> Self {
|
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> {
|
pub async fn run(self) -> Result<ExitCode> {
|
||||||
|
|
|
@ -15,9 +15,9 @@ use super::utils::files::{discover_script_path_including_lune_dirs, strip_sheban
|
||||||
#[derive(Debug, Clone, Parser)]
|
#[derive(Debug, Clone, Parser)]
|
||||||
pub struct RunCommand {
|
pub struct RunCommand {
|
||||||
/// Script name or full path to the file to run
|
/// 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
|
/// Arguments to pass to the script, stored in process.args
|
||||||
script_args: Vec<String>,
|
pub(super) script_args: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RunCommand {
|
impl RunCommand {
|
||||||
|
|
Loading…
Add table
Reference in a new issue