From 0ec2ba493b81428d3d05903cc55f966ae6f7912e Mon Sep 17 00:00:00 2001 From: Nathan Gill Date: Thu, 1 Jan 2026 14:54:57 +0000 Subject: [PATCH] feat: add `plugin verify` subcommand --- src/args.rs | 32 ++++++++++++++++++++++++++++++++ src/main.rs | 19 ++++++++++++++++++- 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/args.rs b/src/args.rs index 1326805..2fb90fe 100644 --- a/src/args.rs +++ b/src/args.rs @@ -43,12 +43,17 @@ pub struct PluginArgs { pub enum PluginSubcommand { List(PluginListArgs), Hash(PluginHashArgs), + Verify(PluginVerifyArgs), } pub struct PluginListArgs { pub config: String, } +pub struct PluginVerifyArgs { + pub config: String, +} + pub struct PluginHashArgs { pub name: String, pub plugin_dir: String, @@ -96,6 +101,14 @@ impl Default for PluginListArgs { } } +impl Default for PluginVerifyArgs { + fn default() -> Self { + Self { + config: DEFAULT_TARS_CONFIG_FILE.to_string(), + } + } +} + fn styles() -> Styles { Styles::styled() .header(AnsiColor::BrightGreen.on_default().effects(Effects::BOLD)) @@ -186,6 +199,18 @@ fn build_cli() -> Command { ) .about("List installed plugins"), ) + .subcommand( + Command::new("verify") + .arg( + Arg::new("config") + .long("config") + .value_name("CONFIG") + .required(false) + .default_value(DEFAULT_TARS_CONFIG_FILE) + .help("Specify the configuration file to use"), + ) + .about("Verify plugin configuration"), + ) .subcommand( Command::new("hash") .arg(Arg::new("name").required(true).help("Plugin name")) @@ -266,6 +291,13 @@ pub fn parse_args() -> Result { plugin_dir: plugin_dir.clone(), }) } + Some(("verify", args)) => { + let config = args.get_one::("config").unwrap(); + + PluginSubcommand::Verify(PluginVerifyArgs { + config: config.clone(), + }) + } _ => { return Err(anyhow!("no subcommand specified")); } diff --git a/src/main.rs b/src/main.rs index 7f7eb4f..cf0d22b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,6 +72,7 @@ async fn main() { if let Err(e) = init_project(&args, &config) { println!("Error initializing project: {e}"); + exit(1); } else { println!("Initialized project in '{}' .", args.path); } @@ -82,14 +83,16 @@ async fn main() { if let Err(e) = builder.build() { println!("{e}"); + exit(1); } } - TarsSubcommand::Clean(args) => { + TarsSubcommand::Clean(args) => { let config = load_config(&args.config); let builder = Builder::new(&config, false); if let Err(e) = builder.clean() { println!("{e}"); + exit(1); } } TarsSubcommand::Serve(args) => { @@ -97,6 +100,7 @@ async fn main() { if let Err(e) = run_server(Arc::new(config)).await { println!("{e}"); + exit(1); } } TarsSubcommand::Plugin(args) => match args.subcommand { @@ -107,6 +111,18 @@ async fn main() { println!("Name: {}, Hook: {:#?}", p.name, p.hook_type); } } + PluginSubcommand::Verify(args) => { + let config = load_config(&args.config); + + for p in config.plugins { + if let Err(e) = p.resolve(Path::new(&config.build.plugin_dir), false) { + println!("Verification failed for {}: {}", p.name, e); + exit(1); + } else { + println!("Verification success for {}", p.name); + } + } + } PluginSubcommand::Hash(args) => { // The actual values don't matter hare, as long as `name` is correct let plugin = Plugin { @@ -121,6 +137,7 @@ async fn main() { } Err(e) => { println!("Error while calculating digest: {e}"); + exit(1); } } }