Skip to content

Commit aa5a6ae

Browse files
authored
feat: implement --interact flag (#118)
1 parent b914b3d commit aa5a6ae

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ cargo r
3535

3636
# To run a script
3737
cargo r -- ./scripts/hello_world.sh
38+
39+
# To run a script and continue in interactive mode
40+
cargo r -- ./scripts/hello_world.sh --interact
3841
```
3942

4043
## License

crates/shell/src/main.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ struct Options {
2020
/// The path to the file that should be executed
2121
file: Option<PathBuf>,
2222

23+
/// Continue in interactive mode after the file has been executed
24+
#[clap(long)]
25+
interact: bool,
26+
2327
#[clap(short, long)]
2428
debug: bool,
2529
}
@@ -30,7 +34,7 @@ fn init_state() -> ShellState {
3034
ShellState::new(env_vars, &cwd, commands::get_commands())
3135
}
3236

33-
async fn interactive() -> miette::Result<()> {
37+
async fn interactive(state: Option<ShellState>) -> miette::Result<()> {
3438
let config = Config::builder()
3539
.history_ignore_space(true)
3640
.completion_type(CompletionType::List)
@@ -46,7 +50,7 @@ async fn interactive() -> miette::Result<()> {
4650
let helper = helper::ShellPromptHelper::default();
4751
rl.set_helper(Some(helper));
4852

49-
let mut state = init_state();
53+
let mut state = state.unwrap_or_else(init_state);
5054

5155
let home = dirs::home_dir().ok_or(miette::miette!("Couldn't get home directory"))?;
5256
let history_file: PathBuf = [home.as_path(), Path::new(".shell_history")]
@@ -151,8 +155,11 @@ async fn main() -> miette::Result<()> {
151155
return Ok(());
152156
}
153157
execute(&script_text, &mut state).await?;
158+
if options.interact {
159+
interactive(Some(state)).await?;
160+
}
154161
} else {
155-
interactive().await?;
162+
interactive(None).await?;
156163
}
157164

158165
Ok(())

0 commit comments

Comments
 (0)