Skip to content

Commit

Permalink
fix: resolve conflicts in main.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
39555 committed Sep 24, 2024
1 parent 8056c94 commit 6627893
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
5 changes: 5 additions & 0 deletions brush-shell/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,14 @@ pub struct CommandLineArgs {
pub enabled_log_events: Vec<events::TraceEvent>,

/// Path to script to execute.
// allow any string as command_name similar to sh
#[clap(allow_hyphen_values = true)]
pub script_path: Option<String>,

/// Arguments for script.
// `allow_hyphen_values`: do not strip `-` from flags
// `num_args=1..`: consume everything
#[clap(allow_hyphen_values = true, num_args=1..)]
pub script_args: Vec<String>,
}

Expand Down
29 changes: 28 additions & 1 deletion brush-shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,41 @@ mod shell_factory;

use crate::args::{CommandLineArgs, InputBackend};
use brush_interactive::InteractiveShell;
use clap::Parser;
use std::{path::Path, sync::Arc};

lazy_static::lazy_static! {
static ref TRACE_EVENT_CONFIG: Arc<tokio::sync::Mutex<Option<events::TraceEventConfig>>> =
Arc::new(tokio::sync::Mutex::new(None));
}

// WARN: this implementation shadows `clap::Parser::parse_from` one so it must be defined
// after the `use clap::Parser`
impl CommandLineArgs {
// Work around clap's limitation handling `--` like a regular value
// TODO: We can safely remove this `impl` after the issue is resolved
// https://github.com/clap-rs/clap/issues/5055
// This function takes precedence over [`clap::Parser::parse_from`]
fn parse_from<'a>(itr: impl IntoIterator<Item = &'a String>) -> Self {
let (mut this, script_args) = brush_core::builtins::parse_known::<CommandLineArgs, _>(itr);
// if we have `--` and unparsed raw args than
script_args.map(|mut args| {
// if script_path has not been parsed yet
// use the first script_args[0] (it is `--`)
// as script_path
let first = args.next();
if this.script_path.is_none() {
this.script_path = first.cloned();
this.script_args.extend(args.cloned());
} else {
// if script_path already exists, everyone goes into script_args
this.script_args
.extend(first.into_iter().chain(args).cloned());
}
});
this
}
}

/// Main entry point for the `brush` shell.
fn main() {
//
Expand Down

0 comments on commit 6627893

Please sign in to comment.