Skip to content

Commit

Permalink
size options
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakub committed Jul 3, 2023
1 parent 5abd147 commit 9f85549
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,7 @@ use crate::tree::FileNode;
use crate::{data_functions, print};
use clap::Parser;

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* ██████╗ ██████╗ ████████╗██╗ ██████╗ ███╗ ██╗███████╗
* ██╔═══██╗██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║██╔════╝
* ██║ ██║██████╔╝ ██║ ██║██║ ██║██╔██╗ ██║███████╗
* ██║ ██║██╔═══╝ ██║ ██║██║ ██║██║╚██╗██║╚════██║
* ╚██████╔╝██║ ██║ ██║╚██████╔╝██║ ╚████║███████║
* ╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

#[derive(PartialEq)]
pub enum Size {
Length,
BlockSize,
Expand Down Expand Up @@ -75,11 +67,23 @@ impl Options {
pub fn compile(input: &ParsingOptions) -> Self {
let mut options = Options::default();

// size
if input.percent {
let (size, _) = options.size;
options.size = (size, true);
}

let (mut size, percent) = options.size;
if size != Size::Length {
if input.block_size {
size = Size::BlockSize
};
if input.blocks {
size = Size::Blocks
};
}
options.size = (size, percent);

if let Some(sort_method) = &input.sort {
options.sort = match sort_method.as_str() {
"name" => Some(data_functions::compare_name),
Expand All @@ -88,34 +92,26 @@ impl Options {
}
}

// verbosity
if input.verbose {
options.verbosity = 2
};
if input.quiet {
options.verbosity = 0
};

// display
if input.decimal {
options.units = (&print::UNITS_DEC, print::DIVISOR_DEC)
};
options.colors = !input.nocolor;

// depth
options.depth = match input.depth {
None => None,
Some(depth) => Some(depth + 1),
};

options.colors = !input.nocolor;

let (_, percent) = options.size;
let mut size = Size::Length;
if input.block_size {
size = Size::BlockSize
};
if input.blocks {
size = Size::Blocks
};
options.size = (size, percent);

options
}
}

0 comments on commit 9f85549

Please sign in to comment.