use clap::{Parser, Subcommand};
use ju_tcs_tbop_24_bb::{head, tail};
use std::path::Path;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
cmd: Commands,
}
#[derive(Subcommand, Debug, Clone)]
enum Commands {
head { n: usize, file: String },
tail { n: usize, file: String },
}
fn print_lines(n: usize, file: String, option: bool) {
let path = Path::new(&file);
let lines = if option { head(path, n) } else { tail(path, n) };
for line in lines {
println!("{}", line);
}
}
fn main() {
let cli = Cli::parse();
match cli.cmd {
Commands::head { n, file } => print_lines(n, file, true),
Commands::tail { n, file } => print_lines(n, file, false),
}
}