Skip to main content

twc_rs/cli/
apps.rs

1// SPDX-FileCopyrightText: 2026 RAprogramm <andrey.rozanov.vl@gmail.com>
2// SPDX-License-Identifier: MIT
3
4//! App platform subcommands and creation arguments.
5
6use clap::Subcommand;
7use clap_complete::engine::ArgValueCompleter;
8
9use super::completers::complete_app;
10
11/// Cloud apps subcommands.
12#[derive(Subcommand, Debug)]
13pub enum AppsCommands {
14    /// List all cloud apps.
15    List,
16    /// Show detailed info for a single app.
17    Info {
18        /// App name or numeric ID.
19        #[arg(
20            value_name = "APP",
21            required_unless_present = "id",
22            add = ArgValueCompleter::new(complete_app)
23        )]
24        app: Option<String>,
25        /// App ID (legacy alias of the positional selector).
26        #[arg(long, conflicts_with = "app")]
27        id:  Option<String>
28    },
29    /// Delete an app.
30    Delete {
31        /// App name or numeric ID.
32        #[arg(
33            value_name = "APP",
34            required_unless_present = "id",
35            add = ArgValueCompleter::new(complete_app)
36        )]
37        app: Option<String>,
38        /// App ID (legacy alias of the positional selector).
39        #[arg(long, conflicts_with = "app")]
40        id:  Option<String>
41    },
42    /// List available app presets (tariffs).
43    ListPresets,
44    /// List configured VCS providers.
45    ListVcsProviders,
46    /// List repositories of a VCS provider.
47    ListRepositories {
48        /// VCS provider ID.
49        #[arg(long)]
50        provider_id: String
51    },
52    /// Create a new app from a connected VCS repository.
53    Create(Box<AppCreateArgs>),
54    /// Show runtime logs of an app.
55    Logs {
56        /// App name or numeric ID.
57        #[arg(
58            value_name = "APP",
59            required_unless_present = "id",
60            add = ArgValueCompleter::new(complete_app)
61        )]
62        app:   Option<String>,
63        /// App ID (legacy alias of the positional selector).
64        #[arg(long, conflicts_with = "app")]
65        id:    Option<String>,
66        /// Show only the last N lines (applied after date filters).
67        #[arg(long)]
68        tail:  Option<usize>,
69        /// Show only lines logged at or after this moment; accepts
70        /// `YYYY-MM-DD` (local midnight) or an RFC 3339 timestamp.
71        #[arg(long, conflicts_with = "today")]
72        since: Option<String>,
73        /// Show only lines logged today (local time).
74        #[arg(long)]
75        today: bool
76    },
77    /// List deploys of an app, newest first.
78    ListDeploys {
79        /// App name or numeric ID.
80        #[arg(
81            value_name = "APP",
82            required_unless_present = "id",
83            add = ArgValueCompleter::new(complete_app)
84        )]
85        app: Option<String>,
86        /// App ID (legacy alias of the positional selector).
87        #[arg(long, conflicts_with = "app")]
88        id:  Option<String>
89    },
90    /// Show build/deploy logs of a deploy (the latest one by default).
91    DeployLogs {
92        /// App name or numeric ID.
93        #[arg(
94            value_name = "APP",
95            required_unless_present = "id",
96            add = ArgValueCompleter::new(complete_app)
97        )]
98        app:       Option<String>,
99        /// App ID (legacy alias of the positional selector).
100        #[arg(long, conflicts_with = "app")]
101        id:        Option<String>,
102        /// Deploy ID (UUID); defaults to the most recent deploy.
103        #[arg(long)]
104        deploy_id: Option<String>,
105        /// Include debug output.
106        #[arg(long)]
107        debug:     bool
108    }
109}
110
111/// Arguments for `apps create` (boxed in the enum to keep variant sizes even).
112#[derive(clap::Args, Debug)]
113pub struct AppCreateArgs {
114    /// App name.
115    #[arg(long)]
116    pub name:          String,
117    /// Optional comment.
118    #[arg(long)]
119    pub comment:       Option<String>,
120    /// VCS provider ID (UUID).
121    #[arg(long)]
122    pub provider_id:   String,
123    /// Repository ID (UUID).
124    #[arg(long)]
125    pub repository_id: String,
126    /// Preset (tariff) ID.
127    #[arg(long)]
128    pub preset_id:     i64,
129    /// App type: backend or frontend.
130    #[arg(long = "type")]
131    pub app_type:      String,
132    /// Framework (e.g. docker, react, next.js, django).
133    #[arg(long)]
134    pub framework:     String,
135    /// Repository branch to build from.
136    #[arg(long, default_value = "main")]
137    pub branch:        String,
138    /// Specific commit SHA (defaults to latest on the branch).
139    #[arg(long)]
140    pub commit_sha:    Option<String>,
141    /// Build command.
142    #[arg(long)]
143    pub build_cmd:     Option<String>,
144    /// Run command (required for backend apps).
145    #[arg(long)]
146    pub run_cmd:       Option<String>,
147    /// Index directory starting with '/' (required for frontend apps).
148    #[arg(long)]
149    pub index_dir:     Option<String>,
150    /// Enable automatic deploy on push.
151    #[arg(long)]
152    pub auto_deploy:   bool,
153    /// Optional project ID to place the app in.
154    #[arg(long)]
155    pub project_id:    Option<i64>
156}