1use crate::{CommandGroup, Runnable, util::SizeFormat};
2use clap::{Args, Parser};
3
4mod commit_stats;
5mod defrag;
6mod df;
7mod du;
8mod label;
9mod mkswapfile;
10mod resize;
11mod show;
12mod sync;
13mod usage;
14
15pub use self::{
16 commit_stats::*, defrag::*, df::*, du::*, label::*, mkswapfile::*,
17 resize::*, show::*, sync::*, usage::*,
18};
19
20#[derive(Parser, Debug)]
27#[clap(arg_required_else_help = true)]
28pub struct FilesystemCommand {
29 #[clap(subcommand)]
30 pub subcommand: FilesystemSubcommand,
31}
32
33impl CommandGroup for FilesystemCommand {
34 fn leaf(&self) -> &dyn Runnable {
35 match &self.subcommand {
36 FilesystemSubcommand::Df(cmd) => cmd,
37 FilesystemSubcommand::Du(cmd) => cmd,
38 FilesystemSubcommand::Show(cmd) => cmd,
39 FilesystemSubcommand::Sync(cmd) => cmd,
40 FilesystemSubcommand::Defragment(cmd) => cmd,
41 FilesystemSubcommand::Resize(cmd) => cmd,
42 FilesystemSubcommand::Label(cmd) => cmd,
43 FilesystemSubcommand::Usage(cmd) => cmd,
44 FilesystemSubcommand::Mkswapfile(cmd) => cmd,
45 FilesystemSubcommand::CommitStats(cmd) => cmd,
46 }
47 }
48}
49
50#[derive(Parser, Debug)]
51pub enum FilesystemSubcommand {
52 Df(FilesystemDfCommand),
53 Du(FilesystemDuCommand),
54 Show(FilesystemShowCommand),
55 Sync(FilesystemSyncCommand),
56 #[clap(alias = "defrag")]
57 Defragment(FilesystemDefragCommand),
58 Resize(FilesystemResizeCommand),
59 Label(FilesystemLabelCommand),
60 Usage(FilesystemUsageCommand),
61 Mkswapfile(FilesystemMkswapfileCommand),
62 CommitStats(FilesystemCommitStatsCommand),
63}
64
65#[derive(Args, Debug)]
71#[allow(clippy::struct_excessive_bools)]
72pub struct UnitMode {
73 #[clap(long, overrides_with_all = ["human_readable", "iec", "si", "kbytes", "mbytes", "gbytes", "tbytes"])]
75 pub raw: bool,
76
77 #[clap(long, overrides_with_all = ["raw", "iec", "si", "kbytes", "mbytes", "gbytes", "tbytes"])]
79 pub human_readable: bool,
80
81 #[clap(long, overrides_with_all = ["raw", "human_readable", "si", "kbytes", "mbytes", "gbytes", "tbytes"])]
83 pub iec: bool,
84
85 #[clap(long, overrides_with_all = ["raw", "human_readable", "iec", "kbytes", "mbytes", "gbytes", "tbytes"])]
87 pub si: bool,
88
89 #[clap(long, overrides_with_all = ["raw", "human_readable", "iec", "si", "mbytes", "gbytes", "tbytes"])]
91 pub kbytes: bool,
92
93 #[clap(long, overrides_with_all = ["raw", "human_readable", "iec", "si", "kbytes", "gbytes", "tbytes"])]
95 pub mbytes: bool,
96
97 #[clap(long, overrides_with_all = ["raw", "human_readable", "iec", "si", "kbytes", "mbytes", "tbytes"])]
99 pub gbytes: bool,
100
101 #[clap(long, overrides_with_all = ["raw", "human_readable", "iec", "si", "kbytes", "mbytes", "gbytes"])]
103 pub tbytes: bool,
104}
105
106impl UnitMode {
107 #[must_use]
109 pub fn resolve(&self) -> SizeFormat {
110 let si = self.si;
111 if self.raw {
112 SizeFormat::Raw
113 } else if self.kbytes {
114 SizeFormat::Fixed(if si { 1000 } else { 1024 })
115 } else if self.mbytes {
116 SizeFormat::Fixed(if si { 1_000_000 } else { 1024 * 1024 })
117 } else if self.gbytes {
118 SizeFormat::Fixed(if si {
119 1_000_000_000
120 } else {
121 1024 * 1024 * 1024
122 })
123 } else if self.tbytes {
124 SizeFormat::Fixed(if si {
125 1_000_000_000_000
126 } else {
127 1024u64.pow(4)
128 })
129 } else if si {
130 SizeFormat::HumanSi
131 } else {
132 SizeFormat::HumanIec
133 }
134 }
135}