use std::path::PathBuf;
use clap::{Parser, Subcommand};
use shadowsocks_gtk_rs::{consts::*, notify_method::NotifyMethod, runtime_api_msg::APICommand};
#[derive(Debug, Clone, Parser)]
#[clap(
name = "ssgtkctl",
author,
version,
about = "A delegate binary for ssgtk that sends commands to the runtime API for your convenience.",
disable_help_subcommand = true,
infer_subcommands = true
)]
pub struct CliArgs {
#[clap(short = 'a', long = "api-socket", value_name = "PATH", default_value_os = RUNTIME_API_SOCKET_PATH_DEFAULT.as_os_str())]
pub runtime_api_socket_path: PathBuf,
#[clap(long = "print-socket-examples")]
pub print_socket_examples: bool,
#[clap(subcommand)]
pub sub_cmd: Option<SubCmd>,
}
#[derive(Debug, Clone, Subcommand)]
#[clap(rename_all = "kebab-case")]
pub enum SubCmd {
LogViewerShow,
LogViewerHide,
SetNotify {
#[clap(index = 1, value_name = "METHOD", value_enum)]
notify_method: NotifyMethod,
},
Restart,
SwitchProfile {
#[clap(index = 1, value_name = "NAME")]
profile_name: String,
},
Stop,
Quit,
}
impl From<SubCmd> for APICommand {
fn from(cmd: SubCmd) -> Self {
match cmd {
SubCmd::LogViewerShow => APICommand::LogViewerShow,
SubCmd::LogViewerHide => APICommand::LogViewerHide,
SubCmd::SetNotify { notify_method } => APICommand::SetNotify(notify_method),
SubCmd::Restart => APICommand::Restart,
SubCmd::SwitchProfile { profile_name } => APICommand::SwitchProfile(profile_name),
SubCmd::Stop => APICommand::Stop,
SubCmd::Quit => APICommand::Quit,
}
}
}