Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Start working on new CLI interface #102

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 3 additions & 57 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ members = [
version = "0.15.26"

[workspace.dependencies]
tokio = { version = "1.39", features = ["full"] }
tokio = { version = "1.40", features = ["full"] }

tracing = "0.1"
tracing-subscriber = "0.3"
Expand Down
2 changes: 0 additions & 2 deletions packages/agent_cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ dirs = { workspace = true }

clap = { version = "4.5", features = ["derive"] }
urlencoding = "2.1"
serde_yaml = "0.9"
crossterm = "0.28"
lazy_static = "1.5"

playit-agent-core = { path = "../agent_core" }
playit-agent-proto = { path = "../agent_proto" }
Expand Down
255 changes: 255 additions & 0 deletions packages/agent_cli/src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,255 @@
use clap::{Args, Parser, Subcommand, ValueEnum};
use uuid::Uuid;

#[derive(Parser, Debug)]
pub struct CliArgs {
#[command(subcommand)]
pub cmd: Option<Commands>,

/* secrets */
#[arg(long)]
pub secret: Option<String>,
#[arg(long("secret-path"), alias = "secret_path")]
pub secret_path: Option<String>,
#[arg(long("secret-wait"), alias = "secret_wait", default_value = "false")]
pub secret_wait: bool,

/* logging */
#[arg(short('s'), long, default_value = "false")]
pub stdout: bool,
#[arg(short('l'), long("log-path"))]
pub log_path: Option<String>,
#[arg(short('i'), default_value = "human")]
pub iface: CliInterface,

/* other opts */
#[arg(long("platform-docker"), alias = "platform_docker", default_value = "false")]
pub platform_docker: bool,
}

#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum CliInterface {
Human,
Json,
Csv,
}

impl Default for CliInterface {
fn default() -> Self {
CliInterface::Human
}
}

#[derive(Subcommand, Debug)]
pub enum Commands {
Version,
#[command(subcommand)]
Account(CmdAccount),
#[command(subcommand)]
Claim(CmdClaim),
Start,
#[command(subcommand)]
Tunnels(CmdTunnels),
Reset,
SecretPath,
#[cfg(target_os = "linux")]
Setup,
}

#[derive(Subcommand, Debug)]
pub enum CmdAccount {
LoginUrl,
}

#[derive(Subcommand, Debug)]
#[command(about = "Commands to setup a new agent")]
pub enum CmdClaim {
Generate,
Url(CmdClaimUrl),
Setup(CmdClaimSetup),
Exchange(CmdClaimExchange),
}

#[derive(Args, Debug)]
#[command(about = "Generate a URL for the user to link the agent to their account")]
pub struct CmdClaimUrl {
#[arg()]
pub claim_code: String,

#[arg(long("name"))]
pub agent_name: Option<String>,
}

#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum CmdAgentType {
SelfManaged,
Asignable,
}

#[derive(Args, Debug)]
#[command(about = "Exchange the claim code for a secret key to operate the agent")]
pub struct CmdClaimSetup {
#[arg()]
pub claim_code: String,

#[arg(long, default_value = "0")]
pub wait: u32,

#[arg(long("type"), default_value = "self-managed")]
pub agent_type: CmdAgentType,
}

#[derive(Args, Debug)]
#[command(about = "Exchange the claim code for a secret key to operate the agent")]
pub struct CmdClaimExchange {
#[arg()]
pub claim_code: String,
}

#[derive(Subcommand, Debug)]
#[command(about = "Commands to manage tunnels")]
pub enum CmdTunnels {
Prepare(CmdTunnelsPrepare),
// Delete(CmdTunnelsDelete),
// Find(CmdTunnelsFind),
// List,
// WaitFor(CmdTunnelsWaitFor),
// Set(CmdTunnelsSet),
}

#[derive(Args, Debug)]
pub struct CmdTunnelsPrepare {
#[arg()]
pub name: String,
#[arg()]
pub tunnel_type: CmdTunnelType,
#[arg()]
pub local_address: String,

#[arg(short('r'), long("region"), default_value = "optimal")]
pub region: CmdTunnelRegion,
#[arg(long("require-region"), default_value = "false")]
pub require_region: bool,
#[arg(long("require-name"), default_value = "false")]
pub require_name: bool,

#[arg(short('c'), long("port-count"), default_value = "1")]
pub port_count: u16,
#[arg(short('u'), long("update-only"), default_value = "false")]
pub update_only: bool,
#[arg(short('n'), long("create-new"))]
pub create_new: Option<bool>,

#[arg(short('p'), long("public-port"))]
pub public_port: Option<u16>,
#[arg(short('d'), long("use-dedicated-ip"))]
pub use_dedicated_ip: Option<String>,

#[arg(short('f'), long("firewall-id"))]
pub firewall_id: Option<Uuid>,

#[arg(short('x'), long("proxy-protocol"))]
pub proxy_protocol: Option<CmdTunnelProxyProtocol>,

#[arg(long, default_value = "0")]
pub wait: u32,
}

#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum CmdTunnelRegion {
GlobalAnycast,
Optimal,
NorthAmerica,
Europe,
Asia,
India,
SouthAmerica,
}

#[derive(Args, Debug)]
pub struct CmdTunnelsFind {
#[arg()]
pub name: String,
#[arg()]
pub tunnel_type: CmdTunnelType,
#[arg(short('c'), long("port-count"), default_value = "1")]
pub port_count: u32,
}

#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum CmdTunnelType {
MinecraftJava,
MinecraftBedrock,
Tcp,
Udp,
Both,
}

#[derive(Args, Debug)]
pub struct CmdTunnelsWaitFor {
pub tunnel_id: Uuid,

#[arg(long, default_value = "0")]
pub wait: u32,
}

#[derive(Args, Debug)]
pub struct CmdTunnelsDelete {
pub tunnel_id: Uuid,

#[arg(long, default_value = "false")]
pub confirm: bool,
}

#[derive(Args, Debug)]
pub struct CmdTunnelsSet {
pub tunnel_id: Uuid,

#[command(subcommand)]
pub command: CmdTunnelsSetCommands,
}

#[derive(Subcommand, Debug)]
pub enum CmdTunnelsSetCommands {
LocalAddress(CmdSetLocalAddress),
Status(CmdSetStatus),
ProxyProtocol(CmdSetProxyProtocol),
Firewall(CmdSetFirewall),
}

#[derive(Args, Debug)]
pub struct CmdSetLocalAddress {
#[arg()]
pub address: String,
}

#[derive(Args, Debug)]
pub struct CmdSetStatus {
#[arg()]
pub status: CmdTunnelStatus,
}

#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum CmdTunnelStatus {
Enabled,
Disabled,
}

#[derive(Args, Debug)]
pub struct CmdSetProxyProtocol {
#[arg()]
pub protocol: CmdTunnelProxyProtocol,
}

#[derive(ValueEnum, Debug, Clone, Copy, PartialEq, Eq)]
pub enum CmdTunnelProxyProtocol {
None,
ProxyProtocolV1,
ProxyProtocolV2,
}

#[derive(Args, Debug)]
pub struct CmdSetFirewall {
#[arg()]
pub firewall_id: Uuid,
}
Loading