use clap::{Args, Parser, Subcommand};
#[derive(Debug, Parser)]
#[command(
name = "gitaway",
version,
about = "Reach your self-hosted git server from anywhere"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
#[derive(Debug, Subcommand)]
pub enum Command {
#[command(subcommand)]
Profile(ProfileCommand),
Use(UseArgs),
Peer(PeerArgs),
#[command(subcommand)]
Key(KeyCommand),
Setup(SetupArgs),
Check(CheckArgs),
}
#[derive(Debug, Args)]
pub struct SetupArgs {
pub name: Option<String>,
#[arg(long, value_name = "FILE")]
pub config: Option<String>,
#[arg(long)]
pub url: Option<String>,
#[arg(long, value_name = "PORT")]
pub ssh_port: Option<String>,
#[arg(long, value_name = "ADDRESS")]
pub inside: Option<String>,
#[arg(long, short)]
pub yes: bool,
}
#[derive(Debug, Args)]
pub struct CheckArgs {
pub profile: Option<String>,
#[arg(long, short)]
pub yes: bool,
}
#[derive(Debug, Args)]
pub struct PeerArgs {
pub profile: Option<String>,
}
#[derive(Debug, Subcommand)]
pub enum KeyCommand {
Rotate {
profile: Option<String>,
#[arg(long, short)]
yes: bool,
},
Import {
profile: Option<String>,
#[arg(long, short)]
yes: bool,
},
}
#[derive(Debug, Subcommand)]
pub enum ProfileCommand {
Add(AddArgs),
List,
Show {
name: String,
},
Remove {
name: String,
#[arg(long, short)]
yes: bool,
},
Default {
name: String,
},
Set {
name: String,
key: String,
value: String,
},
}
#[derive(Debug, Args)]
pub struct AddArgs {
pub name: Option<String>,
#[arg(long)]
pub endpoint: Option<String>,
#[arg(long)]
pub server_public_key: Option<String>,
#[arg(long)]
pub address: Option<String>,
#[arg(long)]
pub home_ssh: Option<String>,
#[arg(long)]
pub host_key: Option<String>,
#[arg(long = "host", value_name = "LAN=TUNNEL")]
pub hosts: Vec<String>,
#[arg(long)]
pub default: bool,
}
#[derive(Debug, Args)]
pub struct UseArgs {
pub profile: String,
}
#[cfg(test)]
mod tests {
use super::*;
use clap::CommandFactory;
#[test]
fn definitions_are_valid() {
Cli::command().debug_assert();
}
}