From 180ac3e17ccd5931d492864d16b25bfc36c17540 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 11 Sep 2024 14:20:20 -0700 Subject: [PATCH 1/4] implement --no-exit --- crates/shell/src/main.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs index 95bf422..1ebc71b 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -42,6 +42,10 @@ struct Options { /// The path to the file that should be executed file: Option, + /// Continue in interactive mode after the file has been executed + #[clap(long)] + no_exit: bool, + #[clap(short, long)] debug: bool, } @@ -52,7 +56,7 @@ fn init_state() -> ShellState { ShellState::new(env_vars, &cwd, commands()) } -async fn interactive() -> anyhow::Result<()> { +async fn interactive(state: Option) -> anyhow::Result<()> { let config = Config::builder() .history_ignore_space(true) .completion_type(CompletionType::Circular) @@ -63,7 +67,7 @@ async fn interactive() -> anyhow::Result<()> { let helper = helper::ShellPromptHelper::default(); rl.set_helper(Some(helper)); - let mut state = init_state(); + let mut state = state.unwrap_or_else(|| init_state()); let home = dirs::home_dir().context("Couldn't get home directory")?; @@ -156,8 +160,11 @@ async fn main() -> anyhow::Result<()> { return Ok(()); } execute(&script_text, &mut state).await?; + if options.no_exit { + interactive(Some(state)).await?; + } } else { - interactive().await?; + interactive(None).await?; } Ok(()) From 247e585aa18c9e4aef065055aa6230e22087f7e2 Mon Sep 17 00:00:00 2001 From: Wolf Vollprecht Date: Wed, 11 Sep 2024 14:26:41 -0700 Subject: [PATCH 2/4] fix clippy --- crates/shell/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs index 1ebc71b..8d69523 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -67,7 +67,7 @@ async fn interactive(state: Option) -> anyhow::Result<()> { let helper = helper::ShellPromptHelper::default(); rl.set_helper(Some(helper)); - let mut state = state.unwrap_or_else(|| init_state()); + let mut state = state.unwrap_or_else(init_state); let home = dirs::home_dir().context("Couldn't get home directory")?; From c5135993e03bcc225a4aaa92f5aa6ddff5ebdd4e Mon Sep 17 00:00:00 2001 From: prsabahrami Date: Mon, 30 Sep 2024 00:24:44 -0400 Subject: [PATCH 3/4] Use --interact instead of --no-exit --- crates/shell/src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/shell/src/main.rs b/crates/shell/src/main.rs index 5ff0d08..b513a6e 100644 --- a/crates/shell/src/main.rs +++ b/crates/shell/src/main.rs @@ -22,7 +22,7 @@ struct Options { /// Continue in interactive mode after the file has been executed #[clap(long)] - no_exit: bool, + interact: bool, #[clap(short, long)] debug: bool, @@ -155,7 +155,7 @@ async fn main() -> miette::Result<()> { return Ok(()); } execute(&script_text, &mut state).await?; - if options.no_exit { + if options.interact { interactive(Some(state)).await?; } } else { From 91564174a9df659d332b195c22d357fdc19111a0 Mon Sep 17 00:00:00 2001 From: prsabahrami Date: Mon, 30 Sep 2024 00:30:36 -0400 Subject: [PATCH 4/4] Update README --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 216f3fd..a86c4d9 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ cargo r # To run a script cargo r -- ./scripts/hello_world.sh + +# To run a script and continue in interactive mode +cargo r -- ./scripts/hello_world.sh --interact ``` ## License