use dip::{bevy::log::LogPlugin, prelude::*}; fn main() { App::new() .add_plugin(CliPlugin::::oneshot()) .add_plugin(ActionPlugin) .add_plugin(TodoActionPlugin) .add_plugin(LogPlugin) .add_system(log_root_arg) .add_system(log_path_flag) .add_system(handle_hello) .add_system(handle_hello2) .add_system(handle_ping) .add_system(handle_add_todo) .add_system(handle_remove_todo) .add_system(handle_list_todo) .run(); } #[derive(CliPlugin, clap::Parser)] #[clap(author, version, about, long_about = None)] struct Cli { root_arg: Option, #[clap(short, long)] path: Option, #[clap(subcommand)] action: Action, } #[derive(SubcommandPlugin, clap::Subcommand, Clone)] pub enum Action { // Unit Ping, // Named Hello { name: Option, }, // Unnamed Hello2(Hello2Args), // Subsubcommand #[clap(subcommand)] Todo(TodoAction), } #[derive(clap::Args, Clone, Debug)] pub struct Hello2Args { name: Option, } #[derive(SubcommandPlugin, clap::Subcommand, Clone, Debug)] pub enum TodoAction { // Unit List, // Named Add { name: Option }, // Unnamed Remove(RemoveTodoAction), } #[derive(clap::Args, Clone, Debug)] pub struct RemoveTodoAction { name: Option, } fn log_root_arg(cli: Res) { if let Some(arg) = &cli.root_arg { info!("root arg: {:?}", arg); } } fn log_path_flag(cli: Res) { if let Some(path) = &cli.path { info!("path flag: {:?}", path); } } fn handle_hello(mut events: EventReader) { for e in events.iter() { info!("Hello, {}!", e.name.clone().unwrap_or("world".to_string())); } } fn handle_hello2(mut events: EventReader) { for e in events.iter() { info!("Hello, {}!", e.name.clone().unwrap_or("world".to_string())); } } fn handle_ping(mut events: EventReader) { for _ in events.iter() { info!("Pong !"); } } fn handle_add_todo(mut events: EventReader) { for e in events.iter() { info!("{e:?}"); info!( "AddTodoAction: {}", e.name.clone().unwrap_or("".to_string()) ); } } fn handle_remove_todo(mut events: EventReader) { for e in events.iter() { info!("{e:?}"); } } fn handle_list_todo(mut events: EventReader) { for e in events.iter() { info!("{e:?}"); } }