Skip to main content

oparry_cli/commands/
wrap.rs

1//! Wrap command - Run Parry wrapper in IPC mode
2//!
3//! This command starts the wrapper that intercepts Claude Code
4//! file operations and validates them in real-time.
5
6use clap::Parser;
7use oparry_core::Result;
8use std::sync::Arc;
9
10use oparry_wrapper::{ClaudeWrapper, ValidatorEngine, WrapConfig};
11
12/// Wrap command configuration
13#[derive(Parser)]
14pub struct WrapCommand {
15    /// Configuration file
16    #[arg(short, long)]
17    pub config: Option<String>,
18
19    /// Don't block writes, only warn
20    #[arg(long, default_value = "false")]
21    pub warn_only: bool,
22
23    /// Verbose output
24    #[arg(short, long)]
25    pub verbose: bool,
26}
27
28impl WrapCommand {
29    pub fn new(config: Option<String>, warn_only: bool, verbose: bool) -> Self {
30        Self { config, warn_only, verbose }
31    }
32
33    pub fn run(self) -> Result<()> {
34        // Setup logging
35        if self.verbose {
36            env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("debug"))
37                .init();
38        } else {
39            env_logger::Builder::from_env(env_logger::Env::default().default_filter_or("info"))
40                .init();
41        }
42
43        // Load or create config
44        let mut config = WrapConfig::default();
45        if self.warn_only {
46            config.block = false;
47        }
48
49        // Create validator engine
50        let validator = Arc::new(ValidatorEngine::new());
51
52        // Create wrapper
53        let wrapper = ClaudeWrapper::new(validator, config);
54
55        // Run IPC loop
56        wrapper.run()
57    }
58}