gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[robocop] branch master updated: add -h/-v command-line options


From: Admin
Subject: [robocop] branch master updated: add -h/-v command-line options
Date: Mon, 09 Jun 2025 00:02:45 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository robocop.

The following commit(s) were added to refs/heads/master by this push:
     new e9b7c1c  add -h/-v command-line options
e9b7c1c is described below

commit e9b7c1c241af6639d0220567c7ac37cb7cc92d40
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Mon Jun 9 00:02:41 2025 +0200

    add -h/-v command-line options
---
 src/main.rs | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 61 insertions(+), 8 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index c6ef2ce..cb6cdec 100644
--- 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();

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]