From 4511c8f9535ec28c2f2e73a1b3a174edf36dee97 Mon Sep 17 00:00:00 2001 From: fluo10 Date: Sat, 14 Jun 2025 09:32:26 +0900 Subject: [PATCH] Add commandline args to switch gui mode --- Cargo.toml | 1 + examples/desktop/Cargo.toml | 1 + examples/desktop/src/cli.rs | 16 ++++++++++++++++ examples/desktop/src/main.rs | 16 +++++++++++++++- lazy-supplements-desktop/Cargo.toml | 2 +- 5 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 examples/desktop/src/cli.rs diff --git a/Cargo.toml b/Cargo.toml index b8a6b5c..465daf3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,6 +10,7 @@ license = "MIT OR Apache-2.0" repository = "https://forgejo.fireturlte.net/lazy-supplements" [workspace.dependencies] +clap = { version = "4.5.38", features = ["derive"] } dioxus = { version = "0.6.0", features = [] } lazy-supplements-core.path = "lazy-supplements-core" libp2p = { version = "0.55.0", features = ["macros", "mdns", "noise", "ping", "tcp", "tokio", "yamux" ] } diff --git a/examples/desktop/Cargo.toml b/examples/desktop/Cargo.toml index a8eb816..701f068 100644 --- a/examples/desktop/Cargo.toml +++ b/examples/desktop/Cargo.toml @@ -6,6 +6,7 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] +clap.workspace = true dioxus.workspace = true lazy-supplements-examples-core.path = "../core" diff --git a/examples/desktop/src/cli.rs b/examples/desktop/src/cli.rs new file mode 100644 index 0000000..b87ca10 --- /dev/null +++ b/examples/desktop/src/cli.rs @@ -0,0 +1,16 @@ +use clap::{Args, Parser}; + +#[derive(Debug, Parser)] +pub struct Cli { + #[command(flatten)] + pub gui_mode: GuiModeArgs +} + +#[derive(Args, Debug)] +#[group(required=true, multiple = false)] +pub struct GuiModeArgs { + #[arg(long)] + pub plain: bool, + #[arg(long)] + pub playful: bool, +} \ No newline at end of file diff --git a/examples/desktop/src/main.rs b/examples/desktop/src/main.rs index e9fdd69..cf4fa2f 100644 --- a/examples/desktop/src/main.rs +++ b/examples/desktop/src/main.rs @@ -1,3 +1,17 @@ +use crate::cli::Cli; +use clap::Parser; + +mod cli; + fn main() { - dioxus::launch(lazy_supplements_examples_core::ui::plain::App); + match Cli::try_parse() { + Ok(x) => { + if x.gui_mode.plain { + dioxus::launch(lazy_supplements_examples_core::ui::plain::App); + } else if x.gui_mode.playful { + todo!() + } + }, + Err(e) => print!("{e}") + } } diff --git a/lazy-supplements-desktop/Cargo.toml b/lazy-supplements-desktop/Cargo.toml index 69842f4..6bce5f9 100644 --- a/lazy-supplements-desktop/Cargo.toml +++ b/lazy-supplements-desktop/Cargo.toml @@ -11,7 +11,7 @@ default = [] test = ["lazy-supplements-core/test"] [dependencies] -clap = { version = "4.5.38", features = ["derive"] } +clap.workspace = true dirs = "6.0.0" lazy-supplements-core.workspace = true libp2p.workspace = true