use clap::Parser;
use clap::command;
use clap::crate_authors;
use std::path::PathBuf;
use std::sync::LazyLock;
pub static SHORT_VERSION: LazyLock<&'static str> = LazyLock::new(|| {
let v = format!(
"{}-{} ({})\nWritten by {}",
env!("CARGO_PKG_VERSION"),
option_env!("VERGEN_GIT_DESCRIBE").unwrap_or("unknown"),
option_env!("VERGEN_BUILD_DATE").unwrap_or("unknown"),
crate_authors!(),
);
Box::leak(v.into_boxed_str())
});
#[derive(Parser, Debug, Default)]
#[command(
version = *SHORT_VERSION,
about,
propagate_version = true,
disable_help_subcommand = true,
args_conflicts_with_subcommands = true
)]
pub struct Cli {
#[command(subcommand)]
pub command: Option<Commands>,
#[command(flatten)]
pub connect: ConnectArgs,
}
#[derive(clap::Subcommand, Debug, Clone)]
pub enum Commands {
Connect(ConnectArgs),
InstallManPages,
InitConfig,
InstallCompletions {
#[clap(default_value = "bash")]
shell: String,
},
}
#[derive(clap::Args, Debug, Clone, Default)]
pub struct ConnectArgs {
#[clap(index = 1)]
pub host: Option<String>,
#[clap(long, short, default_value_t = 22)]
pub port: u16,
#[clap(long, short)]
pub username: Option<String>,
#[clap(long, short = 'k')]
pub private_key: Option<PathBuf>,
#[clap(long, short = 'o')]
pub openssh_certificate: Option<PathBuf>,
#[clap(index = 2)]
pub path: Option<PathBuf>,
#[clap(short, long)]
pub from_config: bool,
}
#[derive(Debug, Clone, Default)]
pub struct ResolvedConnectArgs {
pub host: String,
pub port: u16,
pub username: Option<String>,
pub private_key: PathBuf,
pub openssh_certificate: Option<PathBuf>,
pub path: PathBuf,
}