use std::path::PathBuf; use std::fmt::Debug; use clap::Parser; #[derive(Parser,Debug)] #[command(version)] pub struct Cli { /// The number of lines to skip lines: usize, /// The file to read, or stdin if not given file: Option, /// Skip until N lines matching this #[arg(short,long, conflicts_with = "token")] line: Option, /// Skip lines until N tokens found #[arg(short,long, conflicts_with = "line", required_if_eq("ignore_extras", "true"))] token: Option, /// Only count the first token on each line #[arg(short, long="ignore-extras")] ignore_extras: bool, } pub fn skip(cli: Cli, mut out: F) -> () where F: FnMut(String) -> () { out(String::from("line 2")); } #[cfg(test)] mod tests { use super::*; #[test] fn skip_one_line() { //given let cli = Cli { lines: 1, file: Some(PathBuf::from("tests/two-lines.txt")), line: None, token: None, ignore_extras: false }; let mut lines: Vec = Vec::new(); //when skip(cli, |line| lines.push(line)); //then assert_eq!(lines, vec!["line 2"]); } }