use bevy::prelude::*;
use bevy_console::{AddConsoleCommand, ConsoleCommand, ConsolePlugin, reply};
use clap::Parser;
fn main() {
App::new()
.add_plugins((DefaultPlugins, ConsolePlugin))
.add_systems(Startup, setup_camera_system)
.add_console_command::<LogCommand, _>(log_command)
.run();
}
fn setup_camera_system(mut commands: Commands) {
commands.spawn(Camera2d);
}
#[derive(Parser, ConsoleCommand)]
#[command(name = "log")]
struct LogCommand {
msg: String,
num: Option<i64>,
}
fn log_command(mut log: ConsoleCommand<LogCommand>) {
if let Some(Ok(LogCommand { msg, num })) = log.take() {
let repeat_count = num.unwrap_or(1);
for _ in 0..repeat_count {
reply!(log, "{msg}");
}
log.ok();
}
}