use std::thread;
use std::time::Duration;
use zfish::{Args, Color, Level, Logger, ProgressBar, Style};
fn main() {
let args = Args::parse();
let log_level = if args.has_flag("verbose") || args.has_flag("v") {
Level::Debug
} else {
Level::Info
};
let logger = Logger::new().level(log_level);
if args.has_flag("help") || args.has_flag("h") {
show_help();
return;
}
if args.has_flag("version") {
println!(
"{}",
Color::Cyan
.paint("zfish Example CLI v0.1.0")
.style(Style::Bold)
);
return;
}
let iterations = args
.get_option("iterations")
.and_then(|s| s.parse::<u64>().ok())
.unwrap_or(50);
let output_file = args
.get_option("output")
.map(|s| s.as_str())
.unwrap_or("output.txt");
logger.info(&format!(
"{}",
Color::Green
.paint("Starting application...")
.style(Style::Bold)
));
logger.debug(&format!("Iterations: {}", iterations));
logger.debug(&format!("Output file: {}", output_file));
logger.info("Processing data...");
let mut pb = ProgressBar::new(iterations);
for i in 0..iterations {
thread::sleep(Duration::from_millis(50));
if i % 10 == 0 {
logger.debug(&format!("Processed {} items", i));
}
pb.set(i + 1);
}
pb.finish(&format!("{}", Color::Green.paint("✓ Processing complete!")));
logger.info(&format!(
"Results saved to: {}",
Color::Cyan.paint(output_file)
));
logger.info(&format!(
"{}",
Color::Green.paint("✓ Done!").style(Style::Bold)
));
println!(
"\n{}",
Color::Magenta.paint("=== Summary ===").style(Style::Bold)
);
println!("Processed: {} items", iterations);
println!("Output: {}", output_file);
println!("Status: {}", Color::Green.paint("Success"));
}
fn show_help() {
println!(
"{}",
Color::Cyan.paint("zfish Example CLI").style(Style::Bold)
);
println!();
println!("USAGE:");
println!(" {} [OPTIONS]", std::env::args().next().unwrap());
println!();
println!("OPTIONS:");
println!(" -h, --help Print help information");
println!(" --version Print version");
println!(" -v, --verbose Enable verbose logging");
println!(" --iterations <N> Number of iterations [default: 50]");
println!(" -o, --output <FILE> Output file path [default: output.txt]");
println!();
println!("EXAMPLES:");
println!(" {} --iterations 100", std::env::args().next().unwrap());
println!(
" {} --verbose -o results.txt",
std::env::args().next().unwrap()
);
}