1use std::path::PathBuf;
4
5use clap::Parser;
6
7#[derive(Parser, Debug)]
9#[command(name = "srt")]
10#[command(about = "Sandbox Runtime - enforce filesystem and network restrictions on processes")]
11#[command(version)]
12pub struct Cli {
13 #[arg(short = 'd', long = "debug")]
15 pub debug: bool,
16
17 #[arg(short = 's', long = "settings")]
19 pub settings: Option<PathBuf>,
20
21 #[arg(short = 'c')]
23 pub command: Option<String>,
24
25 #[arg(long = "control-fd")]
27 pub control_fd: Option<i32>,
28
29 #[arg(trailing_var_arg = true)]
31 pub args: Vec<String>,
32}
33
34impl Cli {
35 pub fn parse_args() -> Self {
37 Cli::parse()
38 }
39
40 pub fn get_command(&self) -> Option<(String, bool)> {
45 if let Some(ref cmd) = self.command {
46 Some((cmd.clone(), true))
47 } else if !self.args.is_empty() {
48 let cmd = crate::utils::join_args(&self.args);
50 Some((cmd, false))
51 } else {
52 None
53 }
54 }
55
56 pub fn get_settings_path(&self) -> Option<PathBuf> {
58 self.settings.clone().or_else(crate::config::default_settings_path)
59 }
60}