From 749401108e92fb2d0ebb2ce667e04306357d6172 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sun, 5 May 2024 01:14:34 +0800 Subject: [PATCH] .. --- yazi-cli/src/args.rs | 6 +++--- yazi-cli/src/main.rs | 30 +++++++++++------------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/yazi-cli/src/args.rs b/yazi-cli/src/args.rs index 7e6672c6..3f69cb08 100644 --- a/yazi-cli/src/args.rs +++ b/yazi-cli/src/args.rs @@ -4,14 +4,14 @@ use anyhow::{bail, Result}; use clap::{command, Parser, Subcommand}; #[derive(Parser)] -#[command(name = "ya")] +#[command(name = "Ya", about, long_about = None)] pub(super) struct Args { #[command(subcommand)] - pub(super) command: Option, + pub(super) command: Command, /// Print version #[arg(short = 'V', long)] - pub version: bool, + pub(super) version: bool, } #[derive(Subcommand)] diff --git a/yazi-cli/src/main.rs b/yazi-cli/src/main.rs index 0953fb63..a8c74b03 100644 --- a/yazi-cli/src/main.rs +++ b/yazi-cli/src/main.rs @@ -1,44 +1,36 @@ mod args; -use std::process; - use args::*; use clap::Parser; #[tokio::main] async fn main() -> anyhow::Result<()> { - let args = Args::parse(); - - if args.version { - println!("Ya {}", action_version()); - process::exit(0); + if std::env::args_os().any(|s| s == "-V" || s == "--version") { + println!( + "Ya {} ({} {})", + env!("CARGO_PKG_VERSION"), + env!("VERGEN_GIT_SHA"), + env!("VERGEN_BUILD_DATE") + ); + return Ok(()); } - match &args.command.expect("No command provided") { + match Args::parse().command { Command::Pub(cmd) => { yazi_dds::init(); if let Err(e) = yazi_dds::Client::shot(&cmd.kind, cmd.receiver, None, &cmd.body()?).await { eprintln!("Cannot send message: {e}"); - process::exit(1); + std::process::exit(1); } } Command::PubStatic(cmd) => { yazi_dds::init(); if let Err(e) = yazi_dds::Client::shot(&cmd.kind, 0, Some(cmd.severity), &cmd.body()?).await { eprintln!("Cannot send message: {e}"); - process::exit(1); + std::process::exit(1); } } } Ok(()) } - -fn action_version() -> String { - format!( - "{} ({} {})", - env!("CARGO_PKG_VERSION"), - env!("VERGEN_GIT_SHA"), - env!("VERGEN_BUILD_DATE") - ) -}