This commit is contained in:
ClementTsang 2024-01-10 23:35:49 -05:00
parent fa9580e47e
commit 017a1702b3
No known key found for this signature in database
GPG Key ID: DC3B7867D8D97095

View File

@ -109,34 +109,8 @@ macro_rules! args {
};
}
/// Workaround trait to add builder methods.
trait CommandBuilder {
fn general_args(self) -> Self;
fn style_args(self) -> Self;
fn temperature_args(self) -> Self;
fn process_args(self) -> Self;
fn cpu_args(self) -> Self;
fn mem_args(self) -> Self;
fn network_args(self) -> Self;
fn battery_args(self) -> Self;
fn gpu_args(self) -> Self;
fn other(self) -> Self;
fn add_args(self) -> Self;
}
impl CommandBuilder for Command {
fn general_args(self) -> Command {
let cmd = self.next_help_heading("General Options");
fn general_args(cmd: Command) -> Command {
let cmd = cmd.next_help_heading("General Options");
let autohide_time = Arg::new("autohide_time")
.long("autohide_time")
@ -193,9 +167,7 @@ impl CommandBuilder for Command {
.long("show_table_scroll_position")
.action(ArgAction::SetTrue)
.help("Shows the scroll position tracker in table widgets.")
.long_help(
"Shows the list scroll position tracker in the widget title for table widgets.",
);
.long_help("Shows the list scroll position tracker in the widget title for table widgets.");
let config_location = Arg::new("config_location")
.short('C')
@ -283,7 +255,7 @@ use CPU (3) as the default instead.
.help("The timespan of data stored.")
.long_help("How much data is stored at once in terms of time. Takes a number in milliseconds or a human duration (e.g. 20m), with a minimum of 1 minute. Note higher values will take up more memory. Defaults to 10 minutes.");
let args = args![
cmd.args(args![
autohide_time,
basic,
disable_click,
@ -300,13 +272,11 @@ use CPU (3) as the default instead.
rate,
time_delta,
retention,
];
])
}
cmd.args(args)
}
fn style_args(self) -> Command {
let cmd = self.next_help_heading("Style Options");
fn style_args(cmd: Command) -> Command {
let cmd = cmd.next_help_heading("Style Options");
// TODO: File an issue with manpage, it cannot render charts correctly.
let color = Arg::new("color")
@ -344,10 +314,10 @@ Defaults to \"default\".
);
cmd.arg(color)
}
}
fn temperature_args(self) -> Command {
let cmd = self.next_help_heading("Temperature Options");
fn temperature_args(cmd: Command) -> Command {
let cmd = cmd.next_help_heading("Temperature Options");
let celsius = Arg::new("celsius")
.short('c')
@ -374,13 +344,12 @@ Defaults to \"default\".
kelvin.get_id(),
]);
let args = args![celsius, fahrenheit, kelvin];
cmd.args(args![celsius, fahrenheit, kelvin])
.group(temperature_group)
}
cmd.args(args).group(temperature_group)
}
fn process_args(self) -> Command {
let cmd = self.next_help_heading("Process Options");
fn process_args(cmd: Command) -> Command {
let cmd = cmd.next_help_heading("Process Options");
let case_sensitive = Arg::new("case_sensitive")
.short('S')
@ -460,10 +429,10 @@ Defaults to \"default\".
];
cmd.args(args)
}
}
fn cpu_args(self) -> Command {
let cmd = self.next_help_heading("CPU Options");
fn cpu_args(cmd: Command) -> Command {
let cmd = cmd.next_help_heading("CPU Options");
let hide_avg_cpu = Arg::new("hide_avg_cpu")
.short('a')
@ -474,13 +443,11 @@ Defaults to \"default\".
// let default_avg_cpu = Arg::new("");
let args = args![hide_avg_cpu];
cmd.args(args![hide_avg_cpu])
}
cmd.args(args)
}
fn mem_args(self) -> Command {
let cmd = self.next_help_heading("Memory Options");
fn mem_args(cmd: Command) -> Command {
let cmd = cmd.next_help_heading("Memory Options");
let mem_as_value = Arg::new("mem_as_value")
.long("mem_as_value")
@ -495,16 +462,16 @@ Defaults to \"default\".
.action(ArgAction::SetTrue)
.help("Enable collecting and displaying cache and buffer memory.");
cmd.args([mem_as_value, enable_cache_memory])
cmd.args(args![mem_as_value, enable_cache_memory])
}
#[cfg(target_os = "windows")]
{
cmd.arg(mem_as_value)
}
}
}
fn network_args(self) -> Command {
let cmd = self.next_help_heading("Network Options");
fn network_args(cmd: Command) -> Command {
let cmd = cmd.next_help_heading("Network Options");
let use_old_network_legend = Arg::new("use_old_network_legend")
.long("use_old_network_legend")
@ -525,9 +492,7 @@ Defaults to \"default\".
.long("network_use_log")
.action(ArgAction::SetTrue)
.help("Displays the network widget with a log scale.")
.long_help(
"Displays the network widget with a log scale. Defaults to a non-log scale.",
);
.long_help("Displays the network widget with a log scale. Defaults to a non-log scale.");
let network_use_binary_prefix = Arg::new("network_use_binary_prefix")
.long("network_use_binary_prefix")
@ -537,20 +502,18 @@ Defaults to \"default\".
"Displays the network widget with binary prefixes (i.e. kibibits, mebibits) rather than a decimal prefix (i.e. kilobits, megabits). Defaults to decimal prefixes.",
);
let args = args![
cmd.args(args![
use_old_network_legend,
network_use_bytes,
network_use_log,
network_use_binary_prefix,
];
])
}
cmd.args(args)
}
fn battery_args(self) -> Command {
fn battery_args(cmd: Command) -> Command {
#[cfg(feature = "battery")]
{
let cmd = self.next_help_heading("Battery Options");
let cmd = cmd.next_help_heading("Battery Options");
let battery = Arg::new("battery")
.long("battery")
@ -564,14 +527,14 @@ Defaults to \"default\".
}
#[cfg(not(feature = "battery"))]
{
self
}
cmd
}
}
fn gpu_args(self) -> Command {
fn gpu_args(cmd: Command) -> Command {
#[cfg(feature = "gpu")]
{
let cmd = self.next_help_heading("GPU Options");
let cmd = cmd.next_help_heading("GPU Options");
let enable_gpu = Arg::new("enable_gpu")
.long("enable_gpu")
@ -582,12 +545,12 @@ Defaults to \"default\".
}
#[cfg(not(feature = "gpu"))]
{
self
}
cmd
}
}
fn other(self) -> Command {
let cmd = self.next_help_heading("Other Options");
fn other_args(cmd: Command) -> Command {
let cmd = cmd.next_help_heading("Other Options");
let help = Arg::new("help")
.short('h')
@ -602,20 +565,6 @@ Defaults to \"default\".
.help("Prints version information.");
cmd.args([help, version])
}
fn add_args(self) -> Self {
self.general_args()
.style_args()
.temperature_args()
.process_args()
.cpu_args()
.mem_args()
.network_args()
.battery_args()
.gpu_args()
.other()
}
}
pub fn build_app() -> Command {
@ -626,7 +575,7 @@ pub fn build_app() -> Command {
None => crate_version!(),
};
Command::new(crate_name!())
let cmd = Command::new(crate_name!())
.author(crate_authors!())
.about(crate_description!())
.disable_help_flag(true)
@ -634,8 +583,21 @@ pub fn build_app() -> Command {
.color(ColorChoice::Auto)
.help_template(TEMPLATE)
.override_usage(USAGE)
.version(VERSION)
.add_args()
.version(VERSION);
let cmd = general_args(cmd);
let cmd = style_args(cmd);
let cmd = temperature_args(cmd);
let cmd = process_args(cmd);
let cmd = cpu_args(cmd);
let cmd = mem_args(cmd);
let cmd = network_args(cmd);
let cmd = battery_args(cmd);
let cmd = gpu_args(cmd);
let cmd = other_args(cmd);
#[allow(clippy::let_and_return)]
cmd
}
#[cfg(test)]