Crates.io | bevy_local_commands |
lib.rs | bevy_local_commands |
version | |
source | src |
created_at | 2023-12-21 16:09:00.149076 |
updated_at | 2024-12-06 02:06:03.517239 |
description | Simple local shell commands for the Bevy game engine |
homepage | |
repository | https://github.com/edouardpoitras/bevy_local_commands |
max_upload_size | |
id | 1077152 |
Cargo.toml error: | TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
Bevy plugin to manage local shell commands.
Add the plugin:
// ...
.add_plugins(BevyLocalCommandsPlugin)
// ...
Run shell commands:
fn run_command(mut commands: Commands) {
commands.spawn(LocalCommand::new("bash").args(["-c", "sleep 1 && echo slept"]));
}
See commands started and kill running commands:
fn kill_started_command(mut active_processes: Query<&mut Process>) {
for mut process in active_processes.iter_mut() {
warn!("Killing process {}", process.id());
process.kill().unwrap();
}
}
Receive command output:
fn get_command_output(mut process_output_event: EventReader<ProcessOutput>) {
for output in process_output_event.read() {
info!("Command output for entity {:?}", output.entity);
for line in output.lines() {
info!("Line Output: {}", line);
}
}
}
Send command input:
fn send_command_input(
mut process_output_event: EventReader<ProcessOutput>,
mut active_processes: Query<&mut Process>,
) {
for output in process_output_event.read() {
for line in output.lines() {
if line.ends_with("Prompt String: ") {
let mut process = active_processes.get_mut(output.entity).unwrap();
process.println("Text to send").expect("Failed to write to process");
}
}
}
}
See commands completed:
fn get_completed(mut process_completed_event: EventReader<ProcessCompleted>) {
for completed in process_completed_event.read() {
info!(
"Command completed (Entity - {}, Success - {})",
completed.entity,
completed.exit_status.success()
);
}
}
Retries:
fn retries(mut commands: Commands) {
commands.spawn((
LocalCommand::new("bash").args(["-c", "sleep 1 && invalid-command --that=fails"]),
Retry::Attempts(3) // Attempt the command 3 times before giving up
));
}
Cleanup:
fn cleanup_on_completion(mut commands: Commands) {
commands.spawn((
LocalCommand::new("bash").args(["-c", "sleep 1"]),
Cleanup::DespawnEntity // Will despawn the entity upon process completion
// Cleanup::RemoveComponents // Will remove only this crate's components upon process completion
));
}
Delay:
fn delay_process_start(mut commands: Commands) {
commands.spawn((
LocalCommand::new("bash").args(["-c", "sleep 1"]),
Delay::Fixed(Duration::from_secs(2)), // Start the process after a 2s delay (applies to each retry)
));
}
Chaining:
fn chain_multiple_commands(mut commands: Commands) {
commands.spawn((
Chain::new(vec![
LocalCommand::new("sh").args(["-c", "echo 'First command'"]),
LocalCommand::new("sh").args(["-c", "echo 'Second command'"]),
LocalCommand::new("sh").args(["-c", "echo 'Third command'"]),
]),
Retry::Attempts(2), // Retry applies to any link in the chain
Delay::Fixed(Duration::from_secs(3)), // Wait 3s between retries and chain commands
Cleanup::RemoveComponents // Remove Chain, Retry, Delay, and Cleanup components upon completion
));
}
bevy | bevy_local_commands |
---|---|
0.15 | 0.8 |
0.14 | 0.7 |
0.13 | 0.5 |
0.12 | 0.4 |
0.11 | 0.1 |