use crate::config::web::UiType;
use clap::{Parser, Subcommand, ValueEnum};
use clap_complete::Shell;
use github_proxy::Proxy;
use guess_target::Target;
use serde::{Deserialize, Serialize};
use strum::{EnumString, IntoStaticStr};
pub mod commands;
const CARGO_PKG_VERSION: &str = env!("CARGO_PKG_VERSION");
const GIT_HASH: &str = git_version::git_version!();
const VERSION: &str = const_str::concat!(CARGO_PKG_VERSION, " ", GIT_HASH);
#[derive(Parser, Clone, Debug)]
#[command(name = "mho", version=VERSION)]
#[command(about = "A tool for managing proxy cores like Clash/Mihomo/SingBox", long_about = None)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
#[arg(long, default_value_t = false)]
pub schedule: bool,
}
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
Hash,
Default,
EnumString,
IntoStaticStr,
Serialize,
Deserialize,
ValueEnum,
)]
pub enum UpgradeRepo {
Mho,
#[default]
MhoAssets,
}
impl std::fmt::Display for UpgradeRepo {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
UpgradeRepo::Mho => write!(f, "mho"),
UpgradeRepo::MhoAssets => write!(f, "mho-assets"),
}
}
}
#[derive(Subcommand, Clone, Debug)]
pub enum InstallCommands {
Core,
Ui,
Geo,
Task,
}
#[derive(Subcommand, Clone, Debug)]
pub enum ConfigCommands {
Url {
value: Option<String>,
},
Proxy {
#[arg(ignore_case = true)]
value: Option<Proxy>,
},
Ui {
#[arg(ignore_case = true)]
value: Option<UiType>,
},
Target {
#[arg(ignore_case = true)]
value: Option<Target>,
},
Host {
value: Option<String>,
},
Secret {
value: Option<String>,
},
MaxRuntime {
value: Option<u64>,
},
}
#[derive(Subcommand, Clone, Debug)]
pub enum Commands {
Install {
#[arg(short, long, default_value_t = false)]
force: bool,
#[command(subcommand)]
command: Option<InstallCommands>,
},
Start {
#[arg(short, long, default_value_t = false)]
force: bool,
},
Stop {
#[arg(short, long, default_value_t = false)]
force: bool,
},
Status,
RunTask,
RemoveTask,
UpdateUrl {
#[arg(short, long, default_value_t = false)]
force: bool,
},
Config {
#[command(subcommand)]
command: Option<ConfigCommands>,
},
Upgrade {
#[arg(default_value_t = UpgradeRepo::MhoAssets, ignore_case = true)]
repo: UpgradeRepo,
},
#[command(trailing_var_arg = true, allow_hyphen_values = true)]
Ei { args: Vec<String> },
Completions {
#[arg(ignore_case = true)]
shell: Shell,
},
}