mirror of
https://github.com/ClementTsang/bottom.git
synced 2024-10-26 03:08:08 +03:00
parent
017a1702b3
commit
23c09d3828
@ -109,8 +109,34 @@ macro_rules! args {
|
||||
};
|
||||
}
|
||||
|
||||
fn general_args(cmd: Command) -> Command {
|
||||
let cmd = cmd.next_help_heading("General Options");
|
||||
/// 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");
|
||||
|
||||
let autohide_time = Arg::new("autohide_time")
|
||||
.long("autohide_time")
|
||||
@ -167,7 +193,9 @@ fn general_args(cmd: Command) -> 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')
|
||||
@ -255,7 +283,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.");
|
||||
|
||||
cmd.args(args![
|
||||
let args = args![
|
||||
autohide_time,
|
||||
basic,
|
||||
disable_click,
|
||||
@ -272,11 +300,13 @@ use CPU (3) as the default instead.
|
||||
rate,
|
||||
time_delta,
|
||||
retention,
|
||||
])
|
||||
}
|
||||
];
|
||||
|
||||
fn style_args(cmd: Command) -> Command {
|
||||
let cmd = cmd.next_help_heading("Style Options");
|
||||
cmd.args(args)
|
||||
}
|
||||
|
||||
fn style_args(self) -> Command {
|
||||
let cmd = self.next_help_heading("Style Options");
|
||||
|
||||
// TODO: File an issue with manpage, it cannot render charts correctly.
|
||||
let color = Arg::new("color")
|
||||
@ -314,10 +344,10 @@ Defaults to \"default\".
|
||||
);
|
||||
|
||||
cmd.arg(color)
|
||||
}
|
||||
}
|
||||
|
||||
fn temperature_args(cmd: Command) -> Command {
|
||||
let cmd = cmd.next_help_heading("Temperature Options");
|
||||
fn temperature_args(self) -> Command {
|
||||
let cmd = self.next_help_heading("Temperature Options");
|
||||
|
||||
let celsius = Arg::new("celsius")
|
||||
.short('c')
|
||||
@ -344,12 +374,13 @@ fn temperature_args(cmd: Command) -> Command {
|
||||
kelvin.get_id(),
|
||||
]);
|
||||
|
||||
cmd.args(args![celsius, fahrenheit, kelvin])
|
||||
.group(temperature_group)
|
||||
}
|
||||
let args = args![celsius, fahrenheit, kelvin];
|
||||
|
||||
fn process_args(cmd: Command) -> Command {
|
||||
let cmd = cmd.next_help_heading("Process Options");
|
||||
cmd.args(args).group(temperature_group)
|
||||
}
|
||||
|
||||
fn process_args(self) -> Command {
|
||||
let cmd = self.next_help_heading("Process Options");
|
||||
|
||||
let case_sensitive = Arg::new("case_sensitive")
|
||||
.short('S')
|
||||
@ -429,10 +460,10 @@ fn process_args(cmd: Command) -> Command {
|
||||
];
|
||||
|
||||
cmd.args(args)
|
||||
}
|
||||
}
|
||||
|
||||
fn cpu_args(cmd: Command) -> Command {
|
||||
let cmd = cmd.next_help_heading("CPU Options");
|
||||
fn cpu_args(self) -> Command {
|
||||
let cmd = self.next_help_heading("CPU Options");
|
||||
|
||||
let hide_avg_cpu = Arg::new("hide_avg_cpu")
|
||||
.short('a')
|
||||
@ -443,11 +474,13 @@ fn cpu_args(cmd: Command) -> Command {
|
||||
|
||||
// let default_avg_cpu = Arg::new("");
|
||||
|
||||
cmd.args(args![hide_avg_cpu])
|
||||
}
|
||||
let args = args![hide_avg_cpu];
|
||||
|
||||
fn mem_args(cmd: Command) -> Command {
|
||||
let cmd = cmd.next_help_heading("Memory Options");
|
||||
cmd.args(args)
|
||||
}
|
||||
|
||||
fn mem_args(self) -> Command {
|
||||
let cmd = self.next_help_heading("Memory Options");
|
||||
|
||||
let mem_as_value = Arg::new("mem_as_value")
|
||||
.long("mem_as_value")
|
||||
@ -462,16 +495,16 @@ fn mem_args(cmd: Command) -> Command {
|
||||
.action(ArgAction::SetTrue)
|
||||
.help("Enable collecting and displaying cache and buffer memory.");
|
||||
|
||||
cmd.args(args![mem_as_value, enable_cache_memory])
|
||||
cmd.args([mem_as_value, enable_cache_memory])
|
||||
}
|
||||
#[cfg(target_os = "windows")]
|
||||
{
|
||||
cmd.arg(mem_as_value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn network_args(cmd: Command) -> Command {
|
||||
let cmd = cmd.next_help_heading("Network Options");
|
||||
fn network_args(self) -> Command {
|
||||
let cmd = self.next_help_heading("Network Options");
|
||||
|
||||
let use_old_network_legend = Arg::new("use_old_network_legend")
|
||||
.long("use_old_network_legend")
|
||||
@ -492,7 +525,9 @@ fn network_args(cmd: Command) -> Command {
|
||||
.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")
|
||||
@ -502,18 +537,20 @@ fn network_args(cmd: Command) -> Command {
|
||||
"Displays the network widget with binary prefixes (i.e. kibibits, mebibits) rather than a decimal prefix (i.e. kilobits, megabits). Defaults to decimal prefixes.",
|
||||
);
|
||||
|
||||
cmd.args(args![
|
||||
let args = args![
|
||||
use_old_network_legend,
|
||||
network_use_bytes,
|
||||
network_use_log,
|
||||
network_use_binary_prefix,
|
||||
])
|
||||
}
|
||||
];
|
||||
|
||||
fn battery_args(cmd: Command) -> Command {
|
||||
cmd.args(args)
|
||||
}
|
||||
|
||||
fn battery_args(self) -> Command {
|
||||
#[cfg(feature = "battery")]
|
||||
{
|
||||
let cmd = cmd.next_help_heading("Battery Options");
|
||||
let cmd = self.next_help_heading("Battery Options");
|
||||
|
||||
let battery = Arg::new("battery")
|
||||
.long("battery")
|
||||
@ -527,14 +564,14 @@ fn battery_args(cmd: Command) -> Command {
|
||||
}
|
||||
#[cfg(not(feature = "battery"))]
|
||||
{
|
||||
cmd
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn gpu_args(cmd: Command) -> Command {
|
||||
fn gpu_args(self) -> Command {
|
||||
#[cfg(feature = "gpu")]
|
||||
{
|
||||
let cmd = cmd.next_help_heading("GPU Options");
|
||||
let cmd = self.next_help_heading("GPU Options");
|
||||
|
||||
let enable_gpu = Arg::new("enable_gpu")
|
||||
.long("enable_gpu")
|
||||
@ -545,12 +582,12 @@ fn gpu_args(cmd: Command) -> Command {
|
||||
}
|
||||
#[cfg(not(feature = "gpu"))]
|
||||
{
|
||||
cmd
|
||||
self
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn other_args(cmd: Command) -> Command {
|
||||
let cmd = cmd.next_help_heading("Other Options");
|
||||
fn other(self) -> Command {
|
||||
let cmd = self.next_help_heading("Other Options");
|
||||
|
||||
let help = Arg::new("help")
|
||||
.short('h')
|
||||
@ -565,6 +602,20 @@ fn other_args(cmd: Command) -> Command {
|
||||
.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 {
|
||||
@ -575,7 +626,7 @@ pub fn build_app() -> Command {
|
||||
None => crate_version!(),
|
||||
};
|
||||
|
||||
let cmd = Command::new(crate_name!())
|
||||
Command::new(crate_name!())
|
||||
.author(crate_authors!())
|
||||
.about(crate_description!())
|
||||
.disable_help_flag(true)
|
||||
@ -583,21 +634,8 @@ pub fn build_app() -> Command {
|
||||
.color(ColorChoice::Auto)
|
||||
.help_template(TEMPLATE)
|
||||
.override_usage(USAGE)
|
||||
.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
|
||||
.version(VERSION)
|
||||
.add_args()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Loading…
Reference in New Issue
Block a user