use crate::process;
use clap::builder::Styles;
use clap::builder::styling::{Ansi256Color, AnsiColor, Color, Effects, Style};
use clap::{Parser, Subcommand};
fn default_config_path() -> String {
process::default_config_path()
.to_string_lossy()
.into_owned()
}
const BANNER: &str =
"\n 🦊🦀 \x1b[1;38;5;208mClawShell\x1b[0m \x1b[38;5;208mSecuring OpenClaw\x1b[0m\n";
const fn cli_styles() -> Styles {
const THEME: Option<Color> = Some(Color::Ansi256(Ansi256Color(208)));
Styles::styled()
.header(Style::new().fg_color(THEME).effects(Effects::BOLD))
.usage(Style::new().fg_color(THEME).effects(Effects::BOLD))
.literal(Style::new().fg_color(THEME))
.placeholder(Style::new().fg_color(Some(Color::Ansi(AnsiColor::BrightBlack))))
.valid(
Style::new()
.fg_color(Some(Color::Ansi(AnsiColor::Green)))
.effects(Effects::BOLD),
)
.invalid(
Style::new()
.fg_color(Some(Color::Ansi(AnsiColor::Red)))
.effects(Effects::BOLD),
)
.error(
Style::new()
.fg_color(Some(Color::Ansi(AnsiColor::Red)))
.effects(Effects::BOLD),
)
}
#[derive(Parser)]
#[command(
name = "clawshell",
about = "The security middleware designed to strap onto the OpenClaw ecosystem.",
version,
styles = cli_styles(),
before_help = BANNER,
after_help = "EXAMPLES:\n \
clawshell start Start with default config\n \
clawshell start -c /etc/clawshell/clawshell.toml Start with a custom config\n \
clawshell stop Stop ClawShell\n \
clawshell status Check if ClawShell is running\n \
clawshell restart Restart ClawShell\n \
clawshell logs --level error Show only error logs\n \
clawshell logs --filter \"timeout\" Filter logs by keyword\n \
clawshell config Display current configuration\n \
clawshell config --edit Edit the configuration file\n \
clawshell onboard Set up the clawshell system user\n \
clawshell uninstall Remove ClawShell from the system\n \
clawshell version Show version information"
)]
#[derive(Debug)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Debug, Subcommand)]
pub enum Commands {
#[command(before_help = BANNER)]
Start {
#[arg(short, long, default_value_t = default_config_path())]
config: String,
#[arg(short, long)]
foreground: bool,
},
#[command(before_help = BANNER)]
Stop,
#[command(before_help = BANNER)]
Status,
#[command(before_help = BANNER)]
Restart {
#[arg(short, long, default_value_t = default_config_path())]
config: String,
},
#[command(before_help = BANNER)]
Logs {
#[arg(short, long)]
level: Option<String>,
#[arg(short, long)]
filter: Option<String>,
#[arg(short, long, default_value = "50")]
num: usize,
#[arg(long)]
follow: bool,
},
#[command(before_help = BANNER)]
Config {
#[arg(short = 'f', long = "file", default_value_t = default_config_path())]
config: String,
#[arg(short, long)]
edit: bool,
},
#[command(before_help = BANNER)]
Onboard,
#[command(before_help = BANNER)]
Uninstall {
#[arg(short = 'y', long)]
yes: bool,
},
#[command(before_help = BANNER)]
Version,
}