Skip to content

Commit 5bea172

Browse files
factorydroidechobt
authored andcommitted
fix(cli): validate sandbox mode flag against allowed values
Fixes bounty issue #1420 The -s/--sandbox flag was accepting any string value without validation. Now it uses clap's value_enum to validate against the allowed modes: danger-full-access, read-only, and workspace-write. Invalid values now produce a clear error message showing the possible values.
1 parent 88d385e commit 5bea172

1 file changed

Lines changed: 21 additions & 3 deletions

File tree

cortex-cli/src/main.rs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
//! - Shell completions
1111
1212
use anyhow::Result;
13-
use clap::{Args, CommandFactory, Parser, Subcommand};
13+
use clap::{Args, CommandFactory, Parser, Subcommand, ValueEnum};
1414
use clap_complete::{Shell, generate};
1515
use std::io;
1616
use std::path::PathBuf;
@@ -36,6 +36,24 @@ use cortex_cli::upgrade_cmd::UpgradeCli;
3636
use cortex_cli::{LandlockCommand, SeatbeltCommand, WindowsCommand};
3737
use cortex_common::CliConfigOverrides;
3838

39+
/// Sandbox mode for CLI argument parsing.
40+
///
41+
/// This enum is used by clap for argument validation and help text.
42+
/// It maps directly to the engine's SandboxMode type.
43+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, ValueEnum)]
44+
pub enum CliSandboxMode {
45+
/// Full access, no restrictions (DANGEROUS - use with caution)
46+
#[value(name = "danger-full-access")]
47+
DangerFullAccess,
48+
/// Read-only filesystem access
49+
#[value(name = "read-only")]
50+
ReadOnly,
51+
/// Read access + write to workspace (default)
52+
#[default]
53+
#[value(name = "workspace-write")]
54+
WorkspaceWrite,
55+
}
56+
3957
/// Cortex CLI - AI Coding Agent
4058
///
4159
/// If no subcommand is specified, starts the interactive TUI.
@@ -82,8 +100,8 @@ struct InteractiveArgs {
82100
config_profile: Option<String>,
83101

84102
/// Select the sandbox policy for shell commands
85-
#[arg(long = "sandbox", short = 's')]
86-
sandbox_mode: Option<String>,
103+
#[arg(long = "sandbox", short = 's', value_enum)]
104+
sandbox_mode: Option<CliSandboxMode>,
87105

88106
/// Configure when the model requires human approval
89107
#[arg(long = "ask-for-approval", short = 'a')]

0 commit comments

Comments
 (0)