Skip to main content

zql_cli/core/
settings.rs

1use crate::db::layout::flatten::FlattenVerbose;
2use crate::db::layout::table::TableHeader;
3
4pub enum Layout {
5    CSV,
6    Table,
7    Flatten,
8    Choose,
9}
10
11pub struct Settings {
12    pub layout: Layout,
13    pub header: TableHeader,
14    pub verbose: FlattenVerbose,
15    pub group: Option<String>,
16}
17
18impl Settings {
19    pub fn new() -> Self {
20        Self {
21            layout: Layout::CSV,
22            header: TableHeader::Include,
23            verbose: FlattenVerbose::Quiet,
24            group: None,
25        }
26    }
27
28    pub fn with_layout(mut self, table: bool, flatten: bool) -> Self {
29        self.layout = match (table, flatten) {
30            (false, false) => Layout::CSV,
31            (true, false) => Layout::Table,
32            (false, true) => Layout::Flatten,
33            (true, true) => Layout::Choose,
34        };
35        self
36    }
37
38    pub fn with_header(mut self, raw: bool) -> Self {
39        self.header = if raw {
40            TableHeader::Exclude
41        } else {
42            TableHeader::Include
43        };
44        self
45    }
46
47    pub fn with_verbose(mut self, verbose: bool) -> Self {
48        self.verbose = if verbose {
49            FlattenVerbose::Verbose
50        } else {
51            FlattenVerbose::Quiet
52        };
53        self
54    }
55
56    pub fn with_group(mut self, group: Option<String>) -> Self {
57        self.group = group;
58        self
59    }
60}