Binary: begin moving flag discovery out of program logic
This commit is contained in:
parent
84a0f2c049
commit
5420684061
@ -25,14 +25,14 @@ mod cli;
|
||||
|
||||
static TEMPLATE: &str = "[ {prefix:^30!} ] {wide_bar}{pos:>5.cyan}/{len:5.green}";
|
||||
|
||||
struct Flags {
|
||||
struct ListingFlags {
|
||||
files: bool,
|
||||
color: bool,
|
||||
long: bool,
|
||||
human: bool,
|
||||
}
|
||||
|
||||
impl From<&ArgMatches> for Flags {
|
||||
impl From<&ArgMatches> for ListingFlags {
|
||||
fn from(value: &ArgMatches) -> Self {
|
||||
Self {
|
||||
files: value.get_flag("files"),
|
||||
@ -43,6 +43,39 @@ impl From<&ArgMatches> for Flags {
|
||||
}
|
||||
}
|
||||
|
||||
enum Verbosity {
|
||||
Quiet,
|
||||
Normal,
|
||||
Verbose,
|
||||
}
|
||||
|
||||
impl From<&ArgMatches> for Verbosity {
|
||||
fn from(value: &ArgMatches) -> Self {
|
||||
if matches.get_flag("quiet") {
|
||||
Self::Quiet
|
||||
} else if matches.get_flag("verbose") && !matches.get_flag("stdout") {
|
||||
Self::Verbose
|
||||
} else {
|
||||
Self::Normal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct CreateFlags {
|
||||
algorithm: Algorithm,
|
||||
zstd_compression: Option<i32>,
|
||||
verbosity: Verbosity,
|
||||
stdout: bool,
|
||||
uid: Option<u32>,
|
||||
gid: Option<u32>,
|
||||
}
|
||||
|
||||
impl From<&ArgMatches> for CreateFlags {
|
||||
fn from(value: &ArgMatches) -> Self {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let matches = cli::haggis().get_matches();
|
||||
match matches.subcommand() {
|
||||
@ -318,17 +351,18 @@ fn progress(file: &str, receiver: &mpsc::Receiver<StreamMessage>, len: u64, matc
|
||||
}
|
||||
|
||||
fn print_listing(li: &Listing, matches: &ArgMatches) -> Result<(), haggis::Error> {
|
||||
if matches.get_flag("files") && li.kind == ListingKind::Directory {
|
||||
let flags = ListingFlags::from(matches);
|
||||
if flags.files && li.kind == ListingKind::Directory {
|
||||
return Ok(());
|
||||
}
|
||||
if matches.get_flag("color") {
|
||||
if matches.get_flag("long") {
|
||||
li.print_color(matches.get_flag("human"))?;
|
||||
if flags.color {
|
||||
if flags.long {
|
||||
li.print_color(flags.human)?;
|
||||
} else {
|
||||
li.print_color_simple()?;
|
||||
}
|
||||
} else if matches.get_flag("long") {
|
||||
li.print(matches.get_flag("human"));
|
||||
} else if flags.long {
|
||||
li.print(flags.human);
|
||||
} else {
|
||||
println!("{}", li.name);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user