#![allow(missing_docs)]
use crate::Severity;
use crate::format::{RuleFormat, RuleFormatArg};
use clap::{Parser, Subcommand};
use std::path::PathBuf;
#[derive(Parser)]
#[command(
name = "agent-rules-tool",
about = "Lint and migrate agent rules per agent-rules-spec"
)]
pub struct Cli {
#[command(subcommand)]
pub command: Commands,
}
#[derive(Subcommand)]
pub enum Commands {
Lint {
#[arg(short = 'd', long, conflicts_with = "input_file")]
directory: Option<PathBuf>,
#[arg(short = 'i', long, conflicts_with = "directory")]
input_file: Option<PathBuf>,
#[arg(long, default_value = "error")]
severity: SeverityArg,
#[arg(long)]
report: Option<PathBuf>,
},
Migrate {
#[arg(value_enum)]
from: RuleFormatArg,
#[arg(short = 'd', long, conflicts_with = "input_file")]
directory: Option<PathBuf>,
#[arg(short = 'i', long, conflicts_with = "directory")]
input_file: Option<PathBuf>,
#[arg(long, default_value = "agents")]
to: RuleFormatArg,
#[arg(short = 'o', long)]
output: Option<PathBuf>,
#[arg(long)]
force: bool,
},
}
#[derive(Debug, Clone, Copy, clap::ValueEnum)]
pub enum SeverityArg {
Warn,
Error,
}
impl From<SeverityArg> for Severity {
fn from(arg: SeverityArg) -> Self {
match arg {
SeverityArg::Warn => Severity::Warn,
SeverityArg::Error => Severity::Error,
}
}
}
impl Commands {
pub fn lint_severity(&self) -> Option<Severity> {
match self {
Commands::Lint { severity, .. } => Some((*severity).into()),
_ => None,
}
}
pub fn migrate_to(&self) -> Option<RuleFormat> {
match self {
Commands::Migrate { to, .. } => Some(RuleFormat::from(*to)),
_ => None,
}
}
}