| pub(crate) mod debug_sandbox; |
| mod exit_status; |
| pub(crate) mod login; |
|
|
| use clap::Args; |
| use clap::Parser; |
| use codex_utils_absolute_path::AbsolutePathBuf; |
| use codex_utils_cli::CliConfigOverrides; |
| use codex_utils_cli::ProfileV2Name; |
| use std::path::PathBuf; |
|
|
| pub use debug_sandbox::run_command_under_landlock; |
| pub use debug_sandbox::run_command_under_seatbelt; |
| pub use debug_sandbox::run_command_under_windows_sandbox; |
| pub use login::read_access_token_from_stdin; |
| pub use login::read_api_key_from_stdin; |
| pub use login::run_login_status; |
| pub use login::run_login_with_access_token; |
| pub use login::run_login_with_api_key; |
| pub use login::run_login_with_chatgpt; |
| pub use login::run_login_with_device_code; |
| pub use login::run_login_with_device_code_fallback_to_browser; |
| pub use login::run_logout; |
|
|
| #[derive(Debug, Default, Args)] |
| pub struct SandboxStateArgs { |
| |
| #[arg( |
| long = "sandbox-state-json", |
| value_name = "JSON", |
| conflicts_with_all = ["permissions_profile", "cwd", "include_managed_config"] |
| )] |
| pub sandbox_state_json: Option<String>, |
|
|
| |
| #[arg( |
| long, |
| requires = "sandbox_state_json", |
| value_parser = parse_absolute_path |
| )] |
| pub sandbox_state_readable_root: Vec<AbsolutePathBuf>, |
|
|
| |
| #[arg(long, requires = "sandbox_state_json", default_value_t = false)] |
| pub sandbox_state_disable_network: bool, |
| } |
|
|
| |
| |
| #[derive(Debug, Parser)] |
| pub struct SeatbeltCommand { |
| #[command(flatten)] |
| pub sandbox_state: SandboxStateArgs, |
|
|
| |
| #[arg( |
| long = "permission-profile", |
| alias = "permissions-profile", |
| short = 'P', |
| value_name = "NAME" |
| )] |
| pub permissions_profile: Option<String>, |
|
|
| |
| #[arg(long = "profile", short = 'p')] |
| pub config_profile: Option<ProfileV2Name>, |
|
|
| |
| #[arg( |
| short = 'C', |
| long = "cd", |
| value_name = "DIR", |
| requires = "permissions_profile" |
| )] |
| pub cwd: Option<PathBuf>, |
|
|
| |
| #[arg( |
| long = "include-managed-config", |
| default_value_t = false, |
| requires = "permissions_profile" |
| )] |
| pub include_managed_config: bool, |
|
|
| |
| #[arg(long = "allow-unix-socket", value_parser = parse_absolute_path)] |
| pub allow_unix_sockets: Vec<AbsolutePathBuf>, |
|
|
| |
| #[arg(long = "log-denials", default_value_t = false)] |
| pub log_denials: bool, |
|
|
| #[clap(skip)] |
| pub config_overrides: CliConfigOverrides, |
|
|
| |
| #[arg(trailing_var_arg = true)] |
| pub command: Vec<String>, |
| } |
|
|
| fn parse_absolute_path(raw: &str) -> Result<AbsolutePathBuf, String> { |
| AbsolutePathBuf::relative_to_current_dir(raw) |
| .map_err(|err| format!("invalid path {raw}: {err}")) |
| } |
|
|
| #[derive(Debug, Parser)] |
| pub struct LandlockCommand { |
| #[command(flatten)] |
| pub sandbox_state: SandboxStateArgs, |
|
|
| |
| #[arg( |
| long = "permission-profile", |
| alias = "permissions-profile", |
| short = 'P', |
| value_name = "NAME" |
| )] |
| pub permissions_profile: Option<String>, |
|
|
| |
| #[arg(long = "profile", short = 'p')] |
| pub config_profile: Option<ProfileV2Name>, |
|
|
| |
| #[arg( |
| short = 'C', |
| long = "cd", |
| value_name = "DIR", |
| requires = "permissions_profile" |
| )] |
| pub cwd: Option<PathBuf>, |
|
|
| |
| #[arg( |
| long = "include-managed-config", |
| default_value_t = false, |
| requires = "permissions_profile" |
| )] |
| pub include_managed_config: bool, |
|
|
| #[clap(skip)] |
| pub config_overrides: CliConfigOverrides, |
|
|
| |
| #[arg(trailing_var_arg = true)] |
| pub command: Vec<String>, |
| } |
|
|
| #[derive(Debug, Parser)] |
| pub struct WindowsCommand { |
| #[command(flatten)] |
| pub sandbox_state: SandboxStateArgs, |
|
|
| |
| #[arg( |
| long = "permission-profile", |
| alias = "permissions-profile", |
| short = 'P', |
| value_name = "NAME" |
| )] |
| pub permissions_profile: Option<String>, |
|
|
| |
| #[arg(long = "profile", short = 'p')] |
| pub config_profile: Option<ProfileV2Name>, |
|
|
| |
| #[arg( |
| short = 'C', |
| long = "cd", |
| value_name = "DIR", |
| requires = "permissions_profile" |
| )] |
| pub cwd: Option<PathBuf>, |
|
|
| |
| #[arg( |
| long = "include-managed-config", |
| default_value_t = false, |
| requires = "permissions_profile" |
| )] |
| pub include_managed_config: bool, |
|
|
| #[clap(skip)] |
| pub config_overrides: CliConfigOverrides, |
|
|
| |
| #[arg(trailing_var_arg = true)] |
| pub command: Vec<String>, |
| } |
|
|