robocop

Checks KYC attributes against sanction lists
Log | Files | Refs | Submodules | README | LICENSE

commit e9b7c1c241af6639d0220567c7ac37cb7cc92d40
parent 67ccfc97e548203686af985b8115d110d14bf30f
Author: Christian Grothoff <christian@grothoff.org>
Date:   Mon,  9 Jun 2025 00:02:41 +0200

add -h/-v command-line options

Diffstat:
Msrc/main.rs | 69+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 61 insertions(+), 8 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -20,6 +20,65 @@ use std::env; use std::fs; use std::io::{self, Write, BufRead, BufReader}; use serde_json::{Value, Map}; +use std::process; + +const VERSION: &str = "1.0.0"; + +fn print_version() { + println!("robocop {}", VERSION); +} + +fn print_help() { + println!("Usage: robocop [OPTIONS] <sanctionlist>"); + println!(); + println!("Arguments:"); + println!(" <sanctionlist> Sanction list in JSON to load"); + println!(); + println!("Options:"); + println!(" -h, --help Show this help message and exit"); + println!(" -v, --version Show version information and exit"); +} + +fn print_usage() { + eprintln!("Usage: robocop [OPTIONS] <sanctionlist>"); + eprintln!("Try 'robocop --help' for more information."); +} + + +fn parse_args() -> Option<String> { + let args: Vec<String> = env::args().collect(); + + match args.len() { + 1 => { + // No arguments provided + print_usage(); + process::exit(1); + } + 2 => { + // Single argument + match args[1].as_str() { + "-h" | "--help" => { + print_help(); + process::exit(0); + } + "-v" | "--version" => { + print_version(); + process::exit(0); + } + filename => { + // Return the filename to continue processing + return Some(filename.to_string()); + } + } + } + _ => { + // Too many arguments + print_usage(); + process::exit(1); + } + } +} + // Finite State Machine for efficient string matching #[derive(Debug, Clone)] @@ -239,17 +298,11 @@ fn levenshtein_distance(s1: &str, s2: &str) -> usize { } fn main() -> Result<(), Box<dyn std::error::Error>> { - let args: Vec<String> = env::args().collect(); - if args.len() != 2 { - eprintln!("Usage: {} <json_file>", args[0]); - std::process::exit(1); - } - - let filename = &args[1]; + let filename = parse_args().unwrap(); // Load and pre-process the JSON database let mut engine = MatchingEngine::new(); - engine.load_from_json(filename)?; + engine.load_from_json(&filename)?; // Read JSON objects from stdin let stdin = io::stdin();