Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 10 additions & 3 deletions crates/shell/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
/// The path to the file that should be executed
file: Option<PathBuf>,

/// Continue in interactive mode after the file has been executed
#[clap(long)]
interact: bool,

#[clap(short, long)]
debug: bool,
}
Expand All @@ -30,7 +34,7 @@
ShellState::new(env_vars, &cwd, commands::get_commands())
}

async fn interactive() -> miette::Result<()> {
async fn interactive(state: Option<ShellState>) -> miette::Result<()> {

Check warning on line 37 in crates/shell/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/shell/src/main.rs#L37

Added line #L37 was not covered by tests
let config = Config::builder()
.history_ignore_space(true)
.completion_type(CompletionType::List)
Expand All @@ -46,7 +50,7 @@
let helper = helper::ShellPromptHelper::default();
rl.set_helper(Some(helper));

let mut state = init_state();
let mut state = state.unwrap_or_else(init_state);

Check warning on line 53 in crates/shell/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/shell/src/main.rs#L53

Added line #L53 was not covered by tests

let home = dirs::home_dir().ok_or(miette::miette!("Couldn't get home directory"))?;
let history_file: PathBuf = [home.as_path(), Path::new(".shell_history")]
Expand Down Expand Up @@ -151,8 +155,11 @@
return Ok(());
}
execute(&script_text, &mut state).await?;
if options.interact {
interactive(Some(state)).await?;

Check warning on line 159 in crates/shell/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/shell/src/main.rs#L158-L159

Added lines #L158 - L159 were not covered by tests
}
} else {
interactive().await?;
interactive(None).await?;

Check warning on line 162 in crates/shell/src/main.rs

View check run for this annotation

Codecov / codecov/patch

crates/shell/src/main.rs#L162

Added line #L162 was not covered by tests
}

Ok(())
Expand Down
Loading