summaryrefslogtreecommitdiffstats
path: root/src/cli/args.rs
blob: 5f85a02530f21f9b59c9defee555cdf05aa5606d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
use {
    std::{
        path::PathBuf,
        str::FromStr,
    },
};

#[derive(Debug, clap::Parser)]
/// A tree explorer and a customizable launcher
///
/// Complete documentation lives at https://dystroy.org/broot"
#[clap(author, version, about)]
pub struct Args {

    /// Show the last modified date of files and directories"
    #[clap(short, long, action)]
    pub dates: bool,

    /// Don't show the last modified date"
    #[clap(short='D', long, action)]
    pub no_dates: bool,

    #[clap(short='f', long, action)]
    /// Only show folders
    pub only_folders: bool,

    /// Show folders and files alike
    #[clap(short='F', long, action)]
    pub no_only_folders: bool,

    /// Show filesystem info on top
    #[clap(long, action)]
    pub show_root_fs: bool,

    /// Show git statuses on files and stats on repo
    #[clap(short='g', long, action)]
    pub show_git_info: bool,

    /// Don't show git statuses on files and stats on repo
    #[clap(short='G', long, action)]
    pub no_show_git_info: bool,

    #[clap(long, action)]
    /// Only show files having an interesting git status, including hidden ones
    pub git_status: bool,

    #[clap(short='h', long, action)]
    /// Show hidden files
    pub hidden: bool,

    #[clap(short='H', long, action)]
    /// Don't show hidden files
    pub no_hidden: bool,

    #[clap(short='i', long, action)]
    /// Show git ignored files
    pub git_ignored: bool,

    #[clap(short='I', long, action)]
    /// Don't show git ignored files
    pub no_git_ignored: bool,

    #[clap(short='p', long, action)]
    /// Show permissions
    pub permissions: bool,

    #[clap(short='P', long, action)]
    /// Don't show permissions
    pub no_permissions: bool,

    #[clap(short='s', long, action)]
    /// Show the size of files and directories
    pub sizes: bool,

    #[clap(short='S', long, action)]
    /// Don't show sizes
    pub no_sizes: bool,

    #[clap(long, action)]
    /// Sort by count (only show one level of the tree)
    pub sort_by_count: bool,

    #[clap(long, action)]
    /// Sort by date (only show one level of the tree)
    pub sort_by_date: bool,

    #[clap(long, action)]
    /// Sort by size (only show one level of the tree)
    pub sort_by_size: bool,

    #[clap(long, action)]
    /// Same as sort-by-type-dirs-first
    pub sort_by_type: bool,

    #[clap(long, action)]
    /// Sort by type, directories first (only show one level of the tree)
    pub sort_by_type_dirs_first: bool,

    #[clap(long, action)]
    /// Sort by type, directories last (only show one level of the tree)
    pub sort_by_type_dirs_last: bool,

    /// Sort by size, show ignored and hidden files
    #[clap(short, long, action)]
    pub whale_spotting: bool,

    /// Don't sort
    #[clap(long, action)]
    pub no_sort: bool,

    /// Trim the root too and don't show a scrollbar
    #[clap(short='t', long, action)]
    pub trim_root: bool,

    /// Don't trim the root level, show a scrollbar
    #[clap(short='T', long, action)]
    pub no_trim_root: bool,

    /// Where to write the produced cmd (if any)
    #[clap(long, value_parser)]
    pub outcmd: Option<PathBuf>,

    /// Semicolon separated commands to execute
    #[clap(short, long, value_parser)]
    pub cmd: Option<String>,

    /// Whether to have styles and colors (auto is default and usually OK)
    #[clap(long, arg_enum, value_parser, default_value="auto")]
    pub color: TriBool,

    /// Semicolon separated paths to specific config files"),
    #[clap(long, value_parser)]
    pub conf: Option<String>,

    /// Height (if you don't want to fill the screen or for file export)
    #[clap(long, value_parser)]
    pub height: Option<u16>,

    /// Install or reinstall the br shell function
    #[clap(long, action)]
    pub install: bool,

    /// Where to write the produced cmd (if any)
    #[clap(long, value_parser)]
    pub set_install_state: Option<ShellInstallState>,

    /// Print to stdout the br function for a given shell
    #[clap(long, value_parser)]
    pub print_shell_function: Option<String>,

    /// A socket to listen to for commands
    #[cfg(unix)]
    #[clap(long, value_parser)]
    pub listen: Option<String>,

    /// Ask for the current root of the remote broot
    #[cfg(unix)]
    #[clap(long, action)]
    pub get_root: bool,

    /// Write default conf files in given directory
    #[clap(long, value_parser)]
    pub write_default_conf: Option<PathBuf>,

    /// A socket that broot sends commands to before quitting
    #[cfg(unix)]
    #[clap(long, value_parser)]
    pub send: Option<String>,

    /// Root Directory
    #[clap(value_parser, value_name="FILE")]
    pub root: Option<PathBuf>,
}

/// This is an Option<bool> but I didn't find any way to configure
/// clap to parse an Option<T> as I want
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ArgEnum)]
pub enum TriBool {
    Auto,
    Yes,
    No,
}
impl TriBool {
    pub fn unwrap_or_else<F>(self, f: F) -> bool
    where
        F: FnOnce() -> bool
    {
        match self {
            Self::Auto => f(),
            Self::Yes => true,
            Self::No => false,
        }
    }
}

#[derive(Debug, Clone, Copy, clap::ValueEnum)]
pub enum ShellInstallState {
    Undefined, // before any install, this is the initial state
    Refused,
    Installed,
}
impl FromStr for ShellInstallState {
    type Err = String;
    fn from_str(state: &str) -> Result<Self, Self::Err> {
        match state {
            "undefined" => Ok(Self::Undefined),
            "refused" => Ok(Self::Refused),
            "installed" => Ok(Self::Installed),
            _ => Err(
                // not supposed to happen because claps check the values
                format!("unexpected install state: {:?}", state)
            ),
        }
    }
}