Skip to content
1        10        20        30        40        50        60        70        80        901use clap::{ArgAction, Args, Subcommand};23#[derive(Debug, Args)]4pub struct OnceCli {5    /// Namespace for containers6    #[arg(short = 'n', long, global = true, default_value = "once")]7    pub namespace: String,89    #[command(subcommand)]10    pub command: Option<OnceCommand>,11}1213#[derive(Debug, Subcommand)]14pub enum OnceCommand {15    /// List installed applications16    #[command(alias = "ls")]17    List,18    /// Start an application19    Start(HostArgs),20    /// Stop an application21    Stop(HostArgs),22    /// Remove an application23    #[command(alias = "rm")]24    Remove(RemoveArgs),25    /// Remove all applications and the proxy26    Teardown(TeardownArgs),27    /// Deploy an application from a Docker image28    Deploy(DeployArgs),29    /// Backup an application to a new archive30    Backup(BackupArgs),31    /// Restore an application from a backup archive32    Restore(RestoreArgs),33    /// Update an application's image or settings34    Update(UpdateArgs),35    /// Manage application secret keys36    Keys {37        #[command(subcommand)]38        command: KeysCommand,39    },40    /// Manage scheduled backups and updates41    Background {42        #[command(subcommand)]43        command: BackgroundCommand,44    },45    /// Update Ino to the current project-source version46    SelfUpdate,47    /// Execute a command in an application container48    Exec(ExecArgs),49    /// Print Ino and Once compatibility versions50    Version,51    /// Run the Ino VPS management server52    Server {53        #[command(subcommand)]54        command: ServerCommand,55    },56    /// Manage the app on the remote Ino server57    Remote {58        #[command(subcommand)]59        command: RemoteCommand,60    },61}6263#[derive(Debug, Subcommand)]64pub enum RemoteCommand {65    /// Release this project and create its new deployment app on the remote server66    Create {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)]77pub enum ServerCommand {78    /// Install or reconcile the server app in the selected Once namespace79    Setup(ServerSetupArgs),80    /// Run the server inside its Once-managed container81    Serve,82    /// Manage the local console for apps on a remote Ino server83    Ui {84        #[command(subcommand)]85        command: UiCommand,86    },87}8889#[derive(Debug, Subcommand)]90pub enum UiCommand {91    /// Start the console in the background92    Start(ServerUiArgs),93    /// Stop the background console94    Stop,95    /// Run the console in the foreground96    Run(ServerUiArgs),97}9899#[derive(Debug, Args)]100pub struct ServerUiArgs {101    /// Origin of the Ino server, such as <https://ino.example.com> (defaults to `INO_SERVER_URL`)102    #[arg(long)]103    pub server: Option<String>,104    /// Local port for the console, served on 127.0.0.1105    #[arg(long, default_value_t = 7878)]106    pub port: u16,107    /// Print the console address without opening a browser108    #[arg(long)]109    pub no_open: bool,110}111112#[derive(Debug, Args)]113pub struct ServerSetupArgs {114    /// Public hostname served by the existing Once proxy115    #[arg(long)]116    pub host: String,117    /// Server image tag (defaults to this ino binary's version)118    #[arg(long)]119    pub version: Option<String>,120    /// Internal server port (defaults to 80)121    #[arg(long, default_value_t = 80)]122    pub port: u16,123}124125#[derive(Debug, Args)]126pub struct HostArgs {127    /// Application hostname128    pub host: String,129}130131#[derive(Debug, Args)]132pub struct RemoveArgs {133    /// Application hostname134    pub host: String,135    /// Also remove the application's persistent data volume136    #[arg(long)]137    pub remove_data: bool,138}139140#[derive(Debug, Args)]141pub struct TeardownArgs {142    /// Also remove application data volumes143    #[arg(long)]144    pub remove_data: bool,145}146147#[derive(Debug, Args)]148pub struct ExecArgs {149    /// Application hostname150    pub host: String,151    /// Command and arguments to execute152    #[arg(required = true, trailing_var_arg = true, allow_hyphen_values = true)]153    pub command: Vec<String>,154}155156#[derive(Debug, Args)]157pub struct DeployArgs {158    /// Docker image to deploy159    pub image: String,160    #[command(flatten)]161    pub settings: SettingsFlags,162}163164#[derive(Debug, Args)]165pub struct BackupArgs {166    /// Application hostname167    pub host: String,168    /// Destination backup archive path169    pub filename: std::path::PathBuf,170}171172#[derive(Debug, Args)]173pub struct RestoreArgs {174    /// Backup archive to restore175    pub filename: std::path::PathBuf,176}177178#[derive(Debug, Args)]179pub struct UpdateArgs {180    /// Current application hostname181    #[arg(id = "current_host")]182    pub host: String,183    /// New Docker image for the application184    #[arg(long)]185    pub image: Option<String>,186    #[command(flatten)]187    pub settings: SettingsFlags,188}189190#[derive(Debug, Subcommand)]191pub enum KeysCommand {192    /// Regenerate secret keys and redeploy the application193    Reset(KeysResetArgs),194    /// Set secret keys and redeploy the application195    Set(KeysSetArgs),196}197198#[derive(Debug, Subcommand)]199pub enum BackgroundCommand {200    /// Install an OS service for scheduled tasks201    Install(BackgroundInstallArgs),202    /// Remove the Ino background service203    Uninstall,204    /// Run background tasks in the foreground205    Run(BackgroundRunArgs),206}207208#[derive(Debug, Args)]209pub struct BackgroundInstallArgs {210    /// Stop and disable the existing Once service before installing Ino's service211    #[arg(long)]212    pub take_over_once: bool,213}214215#[derive(Debug, Args)]216pub struct BackgroundRunArgs {217    /// Run one check and exit (useful for manual runs)218    #[arg(long)]219    pub once: bool,220    /// Do not run automatic self-update checks221    #[arg(long)]222    pub no_self_update: bool,223}224225#[derive(Debug, Args)]226pub struct KeysResetArgs {227    /// Application hostname228    pub host: String,229    /// Regenerate `SECRET_KEY_BASE`230    #[arg(long)]231    pub secret_key_base: bool,232    /// Regenerate the VAPID key pair233    #[arg(long)]234    pub vapid: bool,235}236237#[derive(Debug, Args)]238pub struct KeysSetArgs {239    /// Application hostname240    pub host: String,241    /// New `SECRET_KEY_BASE`242    #[arg(long)]243    pub secret_key_base: Option<String>,244    /// New VAPID private key245    #[arg(long)]246    pub vapid: Option<String>,247}248249#[derive(Debug, Clone, Default, Args)]250pub struct SettingsFlags {251    /// Hostname for the application252    #[arg(long)]253    pub host: Option<String>,254    /// Disable TLS for the application255    #[arg(long, default_missing_value = "true", num_args = 0..=1, action = ArgAction::Set)]256    pub disable_tls: Option<bool>,257    /// Application environment variable in KEY=VALUE form (repeatable)258    #[arg(long = "env", action = ArgAction::Append)]259    pub env: Option<Vec<String>>,260    #[arg(long)]261    pub smtp_server: Option<String>,262    #[arg(long)]263    pub smtp_port: Option<String>,264    #[arg(long)]265    pub smtp_username: Option<String>,266    #[arg(long)]267    pub smtp_password: Option<String>,268    #[arg(long)]269    pub smtp_from: Option<String>,270    /// CPU quota271    #[arg(long)]272    pub cpus: Option<u32>,273    /// Memory limit in MB274    #[arg(long)]275    pub 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)]278    pub auto_update: Option<bool>,279    /// Absolute directory used for backups280    #[arg(long)]281    pub backup_path: Option<std::path::PathBuf>,282    /// Enable automatic backups283    #[arg(long, default_missing_value = "true", num_args = 0..=1, action = ArgAction::Set)]284    pub auto_backup: Option<bool>,285    /// Registry username286    #[arg(long)]287    pub registry_username: Option<String>,288    /// Registry password289    #[arg(long, conflicts_with = "registry_password_stdin")]290    pub registry_password: Option<String>,291    /// Read registry password from stdin292    #[arg(long, conflicts_with = "registry_password")]293    pub registry_password_stdin: bool,294}295296#[cfg(test)]297mod tests {298    use clap::Parser;299300    use super::{OnceCommand, SettingsFlags};301302    #[derive(Parser)]303    struct TestCli {304        #[command(subcommand)]305        command: OnceCommand,306    }307308    #[test]309    fn update_boolean_flags_remain_optional_and_parse_explicit_values() {310        let parsed = TestCli::try_parse_from([311            "ino",312            "deploy",313            "basecamp/writebook:latest",314            "--auto-update=false",315            "--disable-tls",316        ])317        .unwrap();318        let OnceCommand::Deploy(args) = parsed.command else {319            panic!("expected deploy command");320        };321        assert_eq!(args.settings.auto_update, Some(false));322        assert_eq!(args.settings.disable_tls, Some(true));323324        let parsed =325            TestCli::try_parse_from(["ino", "deploy", "basecamp/writebook:latest"]).unwrap();326        let OnceCommand::Deploy(args) = parsed.command else {327            panic!("expected deploy command");328        };329        assert_eq!(args.settings.auto_update, None);330        assert_eq!(args.settings.disable_tls, None);331        assert!(SettingsFlags::default().auto_update.is_none());332    }333334    #[test]335    fn update_has_a_current_host_and_optional_new_host() {336        let 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();346        let OnceCommand::Update(args) = parsed.command else {347            panic!("expected update command");348        };349        assert_eq!(args.host, "old.example.test");350        assert_eq!(args.settings.host.as_deref(), Some("new.example.test"));351        assert_eq!(352            args.image.as_deref(),353            Some("registry.example.test/team/app:v2")354        );355    }356357    #[test]358    fn keys_commands_parse_nested_actions_and_flags() {359        let parsed =360            TestCli::try_parse_from(["ino", "keys", "reset", "app.localhost", "--vapid"]).unwrap();361        let OnceCommand::Keys {362            command: super::KeysCommand::Reset(args),363        } = parsed.command364        else {365            panic!("expected keys reset");366        };367        assert_eq!(args.host, "app.localhost");368        assert!(args.vapid);369370        let parsed = TestCli::try_parse_from([371            "ino",372            "keys",373            "set",374            "app.localhost",375            "--secret-key-base",376            "secret",377        ])378        .unwrap();379        let OnceCommand::Keys {380            command: super::KeysCommand::Set(args),381        } = parsed.command382        else {383            panic!("expected keys set");384        };385        assert_eq!(args.secret_key_base.as_deref(), Some("secret"));386    }387}