summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--morphology-cli/src/main.rs39
-rwxr-xr-xtest_pretty.sh9
2 files changed, 39 insertions, 9 deletions
diff --git a/morphology-cli/src/main.rs b/morphology-cli/src/main.rs
index 30c9687..290a97d 100644
--- a/morphology-cli/src/main.rs
+++ b/morphology-cli/src/main.rs
@@ -1,11 +1,13 @@
//! CLI tool to generate all valid meta-affine sequences of a given length.
//!
-//! Usage: generate <length>
+//! Usage: generate [--pretty] <length>
//!
//! Example:
//! generate 5
+//! generate --pretty 5
//!
//! This will list all valid meta-affine sequences of length 5 and print the total count.
+//! With --pretty, values are displayed in nested bracket notation.
use meta_affine::sequence::generate_all_sequences;
use std::env;
@@ -15,19 +17,31 @@ fn main() {
// Parse command-line arguments
let args: Vec<String> = env::args().collect();
- if args.len() != 2 {
- eprintln!("Usage: {} <length>", args[0]);
+ // Check for --pretty flag
+ let pretty = args.contains(&"--pretty".to_string());
+
+ // Filter out flags to get positional arguments
+ let positional: Vec<&String> = args.iter()
+ .skip(1) // Skip program name
+ .filter(|arg| !arg.starts_with("--"))
+ .collect();
+
+ if positional.len() != 1 {
+ eprintln!("Usage: {} [--pretty] <length>", args[0]);
eprintln!("\nGenerates all valid meta-affine sequences of the specified length.");
- eprintln!("\nExample:");
+ eprintln!("\nOptions:");
+ eprintln!(" --pretty Display values in nested bracket notation");
+ eprintln!("\nExamples:");
eprintln!(" {} 5", args[0]);
+ eprintln!(" {} --pretty 5", args[0]);
process::exit(1);
}
- let length: usize = match args[1].parse() {
+ let length: usize = match positional[0].parse() {
Ok(n) => n,
Err(_) => {
eprintln!("Error: Length must be a positive integer");
- eprintln!("Usage: {} <length>", args[0]);
+ eprintln!("Usage: {} [--pretty] <length>", args[0]);
process::exit(1);
}
};
@@ -43,16 +57,23 @@ fn main() {
// Generate all sequences
let sequences = generate_all_sequences(length);
+ // Choose delimiters based on output format
+ let (open, close) = if pretty { ("", "") } else { ("[", "]") };
+
// Print each sequence
for (i, sequence) in sequences.iter().enumerate() {
- print!("{}. [", i + 1);
+ print!("{}. {}", i + 1, open);
for (j, value) in sequence.values().iter().enumerate() {
- print!("{}", value);
+ if pretty {
+ print!("{}", value.pretty_print());
+ } else {
+ print!("{}", value);
+ }
if j < sequence.values().len() - 1 {
print!(", ");
}
}
- println!("]");
+ println!("{}", close);
}
// Print summary
diff --git a/test_pretty.sh b/test_pretty.sh
new file mode 100755
index 0000000..64141d4
--- /dev/null
+++ b/test_pretty.sh
@@ -0,0 +1,9 @@
+#!/bin/bash
+cd /home/a/top/work/app
+echo "Testing specific sequence outputs:"
+echo ""
+echo "Standard output for length 2:"
+cargo run --bin generate -- 2 2>&1 | grep "1\. \[" | head -1
+echo ""
+echo "Pretty output for length 2:"
+cargo run --bin generate -- --pretty 2 2>&1 | grep "1\. \[" | head -1