hyprstream_core/cli/commands/worker.rs
1//! Worker CLI commands
2//!
3//! Provides commands for managing sandboxes (Kata VMs), containers, and images:
4//! - `worker list` - List sandboxes and containers
5//! - `worker run` - Run a container in a sandbox
6//! - `worker stop` - Stop a sandbox or container
7//! - `worker rm` - Remove a sandbox or container
8//! - `worker images` - Image management subcommands
9
10use clap::Subcommand;
11
12/// Worker actions
13#[derive(Subcommand)]
14pub enum WorkerAction {
15 /// List sandboxes and containers
16 List {
17 /// Filter by sandbox ID
18 #[arg(long)]
19 sandbox: Option<String>,
20 /// Filter by container ID
21 #[arg(long)]
22 container: Option<String>,
23 /// Show only containers (not sandboxes)
24 #[arg(long)]
25 containers: bool,
26 /// Show only sandboxes (not containers)
27 #[arg(long)]
28 sandboxes: bool,
29 /// Filter by state (ready, not-ready, running, exited)
30 #[arg(long)]
31 state: Option<String>,
32 /// Show all details
33 #[arg(short, long)]
34 verbose: bool,
35 },
36
37 /// Run a container in a sandbox
38 Run {
39 /// Image reference (e.g., docker.io/library/alpine:latest)
40 image: String,
41 /// Command to run (optional, uses image default)
42 #[arg(trailing_var_arg = true)]
43 command: Vec<String>,
44 /// Sandbox ID to use (creates new if not specified)
45 #[arg(long)]
46 sandbox: Option<String>,
47 /// Container name
48 #[arg(long)]
49 name: Option<String>,
50 /// Environment variables (KEY=VALUE)
51 #[arg(short, long)]
52 env: Vec<String>,
53 /// Working directory
54 #[arg(short, long)]
55 workdir: Option<String>,
56 /// Run in detached mode
57 #[arg(short, long)]
58 detach: bool,
59 /// Remove container after exit
60 #[arg(long)]
61 rm: bool,
62 },
63
64 /// Stop a sandbox or container
65 Stop {
66 /// Sandbox or container ID
67 id: String,
68 /// Timeout in seconds (default: 30)
69 #[arg(short, long, default_value = "30")]
70 timeout: i64,
71 /// Force stop (SIGKILL)
72 #[arg(short, long)]
73 force: bool,
74 },
75
76 /// Start a stopped container
77 Start {
78 /// Container ID
79 container_id: String,
80 },
81
82 /// Restart a sandbox or container
83 Restart {
84 /// Sandbox or container ID
85 id: String,
86 /// Timeout for stop phase
87 #[arg(short, long, default_value = "30")]
88 timeout: i64,
89 },
90
91 /// Remove a sandbox or container
92 Rm {
93 /// Sandbox or container IDs
94 ids: Vec<String>,
95 /// Force removal (stop if running)
96 #[arg(short, long)]
97 force: bool,
98 /// Remove associated volumes
99 #[arg(short, long)]
100 volumes: bool,
101 },
102
103 /// Get detailed status
104 Status {
105 /// Sandbox or container ID
106 id: String,
107 /// Show all details
108 #[arg(short, long)]
109 verbose: bool,
110 },
111
112 /// Get resource usage statistics
113 Stats {
114 /// Sandbox or container IDs (all if empty)
115 ids: Vec<String>,
116 /// Continuous output
117 #[arg(long)]
118 stream: bool,
119 /// Don't print header
120 #[arg(long)]
121 no_header: bool,
122 },
123
124 /// Execute command in container
125 Exec {
126 /// Container ID
127 container_id: String,
128 /// Command to execute
129 #[arg(trailing_var_arg = true)]
130 command: Vec<String>,
131 /// Timeout in seconds (default: 60)
132 #[arg(short, long, default_value = "60")]
133 timeout: i64,
134 },
135
136 /// Attach to container terminal (tmux-like streaming I/O)
137 Terminal {
138 /// Container ID
139 container_id: String,
140 /// Detach key sequence (default: ctrl-])
141 #[arg(long, default_value = "ctrl-]")]
142 detach_keys: String,
143 },
144
145 /// Image management commands
146 #[command(subcommand)]
147 Images(ImageCommand),
148}
149
150/// Image management subcommands
151#[derive(Subcommand)]
152pub enum ImageCommand {
153 /// List cached images
154 List {
155 /// Show all details
156 #[arg(short, long)]
157 verbose: bool,
158 /// Filter by reference pattern
159 #[arg(long)]
160 filter: Option<String>,
161 },
162
163 /// Pull an image from registry
164 Pull {
165 /// Image reference (e.g., docker.io/library/alpine:latest)
166 image: String,
167 /// Registry username
168 #[arg(short, long)]
169 username: Option<String>,
170 /// Registry password
171 #[arg(short, long)]
172 password: Option<String>,
173 },
174
175 /// Remove an image
176 Rm {
177 /// Image references to remove
178 images: Vec<String>,
179 /// Force removal even if in use
180 #[arg(short, long)]
181 force: bool,
182 },
183
184 /// Show image filesystem usage
185 Df,
186}