Expand description
§croshet
A cross-platform UNIX-like shell scripting library, developed by pesde primarily to solve the annoying rimraf problem.
§Examples
§Shorthand macro
Execute a singular command, or run them in bulk without much control over how:
println!(
"singular exec result: {}, bulk exec results: {:?}",
sh!("echo hello, croshet!").await?,
sh!["echo $(pwd)", "mkdir hi_mom", "rm -rf hi_mom", "exit 1"].await?
);§Manual execution
Lower level API to manually run commands with full control over the options and lifecycle of the process:
// Parse the text
let list = croshet::parser::parse(&text)?;
let kill_signal = KillSignal::default();
let options = croshet::ExecuteOptionsBuilder::new()
.args(std::env::args_os().collect()) // Args to be passed to the shell itself
.env_vars(std::env::vars_os().collect()) // Environment variables that are set globally
.cwd(std::env::current_dir()?) // The working directory of the shell process
.custom_commands(...) // HashMap of custom commands to be defined
.kill_signal(kill_signal.clone()) // Pass the kill signal to control termination fo the process
.stdin(croshet::ShellPipeReader::stdin()) // The standard input pipe
.stdout(croshet::ShellPipeWriter::stdout()) // The standard output pipe
.stderr(croshet::ShellPipeWriter::stderr()) // The standard error pipe
.build()?;
// Execute!
println!("Command exited with code: {}", croshet::execute(list.clone(), options.clone()).await);
// ...Or, execute with a timeout
// Set up a separate task to cancel the execution in 5s
tokio::task::spawn(async move {
tokio::time::sleep(tokio::time::Duration::from_secs(5)).await;
kill_signal.send(croshet::SignalKind::SIGKILL);
});
let exit_code = croshet::execute(list, options).await;
println!("Command exited with code: {}", exit_code);§What’s with the name?
This project was initially forked from Deno’s deno_task_shell, which we found a bit too boring of a name :p
Instead, we settled for the name croshet, pronounced /kroʊˈʃeɪ/ (or simply, ‘crochet’), as the library “crochets together” several UNIX-y shell features (most POSIX sh and some bash features, common UNIX command line tools, etc.) with a bit of shell related flair.
Modules§
Macros§
- sh
- Macro to simplify running command(s) without having to construct a
SequentialListand pass options manually. The macro results in aFuturereturning aResultwith ani32or aVec<i32>when executing in bulk. Sets the working directory to the process’ working directory.
Structs§
- Error
- An error originating in croshet, wrapping around any dynamic error, including (but not limited to), command syntax parsing, execution, or standard library errors.
- Executable
Command - Command that resolves the command name and executes it in a separate process.
- Execute
Command Args Context - Execute
Options - Options for executing a command or process.
- Execute
Options Builder - Builder pattern constructor for
ExecuteOptions. - Kill
Signal - Used to send signals to commands.
- Kill
Signal Drop Guard - Guard that on drop will send a signal on the associated
KillSignal. - Shell
Command Context - Shell
State
Enums§
- Command
Path Resolution Error - Error when a command path could not be resolved.
- EnvChange
- Execute
Result - Shell
Pipe Reader - Reader side of a pipe.
- Shell
Pipe Writer - Writer side of a pipe.
- Signal
Kind
Traits§
Functions§
- execute
- Executes a
SequentialListof commands in a croshet environment. - pipe
- Used to communicate between commands.