LINE1 10 20 30 40 50 60 70 80 901use clap::{ArgAction, Args, Subcommand};23#[derive(Debug, Args)]4pubstructOnceCli {5/// Namespace for containers6#[arg(short = 'n', long, global = true, default_value = "once")]7pub namespace: String,89#[command(subcommand)]10pub command: Option<OnceCommand>,11}1213#[derive(Debug, Subcommand)]14pubenumOnceCommand {15/// List installed applications16#[command(alias = "ls")]17List,18/// Start an application19Start(HostArgs),20/// Stop an application21Stop(HostArgs),22/// Remove an application23#[command(alias = "rm")]24Remove(RemoveArgs),25/// Remove all applications and the proxy26Teardown(TeardownArgs),27/// Deploy an application from a Docker image28Deploy(DeployArgs),29/// Backup an application to a new archive30Backup(BackupArgs),31/// Restore an application from a backup archive32Restore(RestoreArgs),33/// Update an application's image or settings34Update(UpdateArgs),35/// Manage application secret keys36Keys {37#[command(subcommand)]38 command: KeysCommand,39 },40/// Manage scheduled backups and updates41Background {42#[command(subcommand)]43 command: BackgroundCommand,44 },45/// Update Ino to the current project-source version46SelfUpdate,47/// Execute a command in an application container48Exec(ExecArgs),49/// Print Ino and Once compatibility versions50Version,51/// Run the Ino VPS management server52Server {53#[command(subcommand)]54 command: ServerCommand,55 },56/// Manage the app on the remote Ino server57Remote {58#[command(subcommand)]59 command: RemoteCommand,60 },61}6263#[derive(Debug, Subcommand)]64pubenumRemoteCommand {65/// Release this project and create its new deployment app on the remote server66Create {67/// Read the app's environment from a KEY=VALUE file (`-` for stdin) instead of prompting68#[arg(long, value_name = "PATH")]69 env_file: Option<std::path::PathBuf>,70/// Skip the confirmation prompts71#[arg(long)]72 yes: bool,73 },74}7576#[derive(Debug, Subcommand)]77pubenumServerCommand {78/// Install or reconcile the server app in the selected Once namespace79Setup(ServerSetupArgs),80/// Run the server inside its Once-managed container81Serve,82/// Manage the local console for apps on a remote Ino server83Ui {84#[command(subcommand)]85 command: UiCommand,86 },87}8889#[derive(Debug, Subcommand)]90pubenumUiCommand {91/// Start the console in the background92Start(ServerUiArgs),93/// Stop the background console94Stop,95/// Run the console in the foreground96Run(ServerUiArgs),97}9899#[derive(Debug, Args)]100pubstructServerUiArgs {101/// Origin of the Ino server, such as <https://ino.example.com> (defaults to `INO_SERVER_URL`)102#[arg(long)]103pub server: Option<String>,104/// Local port for the console, served on 127.0.0.1105#[arg(long, default_value_t = 7878)]106pub port: u16,107/// Print the console address without opening a browser108#[arg(long)]109pub no_open: bool,110}111112#[derive(Debug, Args)]113pubstructServerSetupArgs {114/// Public hostname served by the existing Once proxy115#[arg(long)]116pub host: String,117/// Server image tag (defaults to this ino binary's version)118#[arg(long)]119pub version: Option<String>,120/// Internal server port (defaults to 80)121#[arg(long, default_value_t = 80)]122pub port: u16,123}124125#[derive(Debug, Args)]126pubstructHostArgs {127/// Application hostname128pub host: String,129}130131#[derive(Debug, Args)]132pubstructRemoveArgs {133/// Application hostname134pub host: String,135/// Also remove the application's persistent data volume136#[arg(long)]137pub remove_data: bool,138}139140#[derive(Debug, Args)]141pubstructTeardownArgs {142/// Also remove application data volumes143#[arg(long)]144pub remove_data: bool,145}146147#[derive(Debug, Args)]148pubstructExecArgs {149/// Application hostname150pub host: String,151/// Command and arguments to execute152#[arg(required = true, trailing_var_arg = true, allow_hyphen_values = true)]153pub command: Vec<String>,154}155156#[derive(Debug, Args)]157pubstructDeployArgs {158/// Docker image to deploy159pub image: String,160#[command(flatten)]161pub settings: SettingsFlags,162}163164#[derive(Debug, Args)]165pubstructBackupArgs {166/// Application hostname167pub host: String,168/// Destination backup archive path169pub filename: std::path::PathBuf,170}171172#[derive(Debug, Args)]173pubstructRestoreArgs {174/// Backup archive to restore175pub filename: std::path::PathBuf,176}177178#[derive(Debug, Args)]179pubstructUpdateArgs {180/// Current application hostname181#[arg(id = "current_host")]182pub host: String,183/// New Docker image for the application184#[arg(long)]185pub image: Option<String>,186#[command(flatten)]187pub settings: SettingsFlags,188}189190#[derive(Debug, Subcommand)]191pubenumKeysCommand {192/// Regenerate secret keys and redeploy the application193Reset(KeysResetArgs),194/// Set secret keys and redeploy the application195Set(KeysSetArgs),196}197198#[derive(Debug, Subcommand)]199pubenumBackgroundCommand {200/// Install an OS service for scheduled tasks201Install(BackgroundInstallArgs),202/// Remove the Ino background service203Uninstall,204/// Run background tasks in the foreground205Run(BackgroundRunArgs),206}207208#[derive(Debug, Args)]209pubstructBackgroundInstallArgs {210/// Stop and disable the existing Once service before installing Ino's service211#[arg(long)]212pub take_over_once: bool,213}214215#[derive(Debug, Args)]216pubstructBackgroundRunArgs {217/// Run one check and exit (useful for manual runs)218#[arg(long)]219pub once: bool,220/// Do not run automatic self-update checks221#[arg(long)]222pub no_self_update: bool,223}224225#[derive(Debug, Args)]226pubstructKeysResetArgs {227/// Application hostname228pub host: String,229/// Regenerate `SECRET_KEY_BASE`230#[arg(long)]231pub secret_key_base: bool,232/// Regenerate the VAPID key pair233#[arg(long)]234pub vapid: bool,235}236237#[derive(Debug, Args)]238pubstructKeysSetArgs {239/// Application hostname240pub host: String,241/// New `SECRET_KEY_BASE`242#[arg(long)]243pub secret_key_base: Option<String>,244/// New VAPID private key245#[arg(long)]246pub vapid: Option<String>,247}248249#[derive(Debug, Clone, Default, Args)]250pubstructSettingsFlags {251/// Hostname for the application252#[arg(long)]253pub host: Option<String>,254/// Disable TLS for the application255#[arg(long, default_missing_value = "true", num_args = 0..=1, action = ArgAction::Set)]256pub disable_tls: Option<bool>,257/// Application environment variable in KEY=VALUE form (repeatable)258#[arg(long = "env", action = ArgAction::Append)]259pub env: Option<Vec<String>>,260#[arg(long)]261pub smtp_server: Option<String>,262#[arg(long)]263pub smtp_port: Option<String>,264#[arg(long)]265pub smtp_username: Option<String>,266#[arg(long)]267pub smtp_password: Option<String>,268#[arg(long)]269pub smtp_from: Option<String>,270/// CPU quota271#[arg(long)]272pub cpus: Option<u32>,273/// Memory limit in MB274#[arg(long)]275pub memory: Option<u32>,276/// Automatically update the app (can be set to false)277#[arg(long, default_missing_value = "true", num_args = 0..=1, action = ArgAction::Set)]278pub auto_update: Option<bool>,279/// Absolute directory used for backups280#[arg(long)]281pub backup_path: Option<std::path::PathBuf>,282/// Enable automatic backups283#[arg(long, default_missing_value = "true", num_args = 0..=1, action = ArgAction::Set)]284pub auto_backup: Option<bool>,285/// Registry username286#[arg(long)]287pub registry_username: Option<String>,288/// Registry password289#[arg(long, conflicts_with = "registry_password_stdin")]290pub registry_password: Option<String>,291/// Read registry password from stdin292#[arg(long, conflicts_with = "registry_password")]293pub registry_password_stdin: bool,294}295296#[cfg(test)]297mod tests {298use clap::Parser;299300usesuper::{OnceCommand, SettingsFlags};301302#[derive(Parser)]303structTestCli {304#[command(subcommand)]305 command: OnceCommand,306 }307308#[test]309fnupdate_boolean_flags_remain_optional_and_parse_explicit_values() {310let parsed = TestCli::try_parse_from([311"ino",312"deploy",313"basecamp/writebook:latest",314"--auto-update=false",315"--disable-tls",316 ])317 .unwrap();318letOnceCommand::Deploy(args) = parsed.command else {319panic!("expected deploy command");320 };321assert_eq!(args.settings.auto_update, Some(false));322assert_eq!(args.settings.disable_tls, Some(true));323324let parsed =325TestCli::try_parse_from(["ino", "deploy", "basecamp/writebook:latest"]).unwrap();326letOnceCommand::Deploy(args) = parsed.command else {327panic!("expected deploy command");328 };329assert_eq!(args.settings.auto_update, None);330assert_eq!(args.settings.disable_tls, None);331assert!(SettingsFlags::default().auto_update.is_none());332 }333334#[test]335fnupdate_has_a_current_host_and_optional_new_host() {336let parsed = TestCli::try_parse_from([337"ino",338"update",339"old.example.test",340"--host",341"new.example.test",342"--image",343"registry.example.test/team/app:v2",344 ])345 .unwrap();346letOnceCommand::Update(args) = parsed.command else {347panic!("expected update command");348 };349assert_eq!(args.host, "old.example.test");350assert_eq!(args.settings.host.as_deref(), Some("new.example.test"));351assert_eq!(352 args.image.as_deref(),353Some("registry.example.test/team/app:v2")354 );355 }356357#[test]358fnkeys_commands_parse_nested_actions_and_flags() {359let parsed =360TestCli::try_parse_from(["ino", "keys", "reset", "app.localhost", "--vapid"]).unwrap();361letOnceCommand::Keys {362 command: super::KeysCommand::Reset(args),363 } = parsed.command364else {365panic!("expected keys reset");366 };367assert_eq!(args.host, "app.localhost");368assert!(args.vapid);369370let parsed = TestCli::try_parse_from([371"ino",372"keys",373"set",374"app.localhost",375"--secret-key-base",376"secret",377 ])378 .unwrap();379letOnceCommand::Keys {380 command: super::KeysCommand::Set(args),381 } = parsed.command382else {383panic!("expected keys set");384 };385assert_eq!(args.secret_key_base.as_deref(), Some("secret"));386 }387}