From 0d8761e5f907d173c40a2a44f3a1d8d8ce5a2f6e Mon Sep 17 00:00:00 2001 From: Weicao-CatilGrass <1992414357@qq.com> Date: Mon, 9 Jun 2025 12:06:15 +0800 Subject: . --- console/Cargo.toml | 1 + console/src/bin/padc.rs | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'console') diff --git a/console/Cargo.toml b/console/Cargo.toml index 57860c7..5c6a313 100644 --- a/console/Cargo.toml +++ b/console/Cargo.toml @@ -8,6 +8,7 @@ version.workspace = true nogamepads = { path = "../../NoGamepads" } nogamepads-core = { path = "../core" } clap = { version = "4.5.38", features = ["derive"] } +clap_complete = "4.5.52" serde = { version = "1.0.219", features = ["derive"] } serde_yaml = "0.9.34" tokio = { version = "1.45.0", features = ["full"] } diff --git a/console/src/bin/padc.rs b/console/src/bin/padc.rs index 720cbea..3323de7 100644 --- a/console/src/bin/padc.rs +++ b/console/src/bin/padc.rs @@ -7,6 +7,7 @@ use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::env::current_dir; use std::fs::File; +use std::io; use std::io::{BufReader, Write}; use std::net::SocketAddr; use std::path::PathBuf; @@ -15,6 +16,7 @@ use std::str::FromStr; use std::sync::{Arc, Mutex}; use std::sync::atomic::Ordering::SeqCst; use std::time::Duration; +use clap_complete::{generate, Shell}; use log::{info, LevelFilter}; use tokio::select; use tokio::signal::ctrl_c; @@ -31,8 +33,8 @@ use nogamepads_core::service::tcp_network::pad_client::structs::PadClientNetwork use nogamepads_core::service::tcp_network::pad_server::structs::PadServerNetwork; #[derive(Parser, Debug)] -#[command(author, version, about, long_about = None)] -struct ConsoleCli { +#[command(version, color = ColorChoice::Auto)] +struct Padc { #[command(subcommand)] command: Commands, } @@ -40,6 +42,11 @@ struct ConsoleCli { #[derive(Subcommand, Debug)] enum Commands { + GenerateCompletion { + #[arg(value_enum)] + shell: Shell, + }, + #[command(subcommand, about = "Manage accounts")] Account(AccountCommands), @@ -257,10 +264,15 @@ struct LocalControllerData { } fn main () { - let cli = ConsoleCli::parse(); + let cli = Padc::parse(); let mut data = read(); match cli.command { + Commands::GenerateCompletion {shell} => { + let mut cmd = Padc::command(); + generate(shell, &mut cmd.clone(), "padc", &mut io::stdout()); + } + Commands::Account(cmds) => { match cmds { AccountCommands::Add(args) => { -- cgit