diff options
Diffstat (limited to 'src/options/args.rs')
-rw-r--r-- | src/options/args.rs | 260 |
1 files changed, 128 insertions, 132 deletions
diff --git a/src/options/args.rs b/src/options/args.rs index a2182577..b410eba4 100644 --- a/src/options/args.rs +++ b/src/options/args.rs @@ -3,80 +3,12 @@ //! Note that you probably want to keep this as a single file so the build script doesn't //! trip all over itself. +// TODO: New sections are misaligned! See if we can get that fixed. + use std::cmp::Ordering; -use clap::{builder::PossibleValuesParser, *}; - -const DEFAULT_WIDGET_TYPE_STR: &str = { - #[cfg(feature = "battery")] - { - "\ -Sets which widget type to use as the default widget. -For the default layout, this defaults to the 'process' widget. -For a custom layout, it defaults to the first widget it sees. - -For example, suppose we have a layout that looks like: -+-------------------+-----------------------+ -| CPU (1) | CPU (2) | -+---------+---------+-------------+---------+ -| Process | CPU (3) | Temperature | CPU (4) | -+---------+---------+-------------+---------+ - -Setting '--default_widget_type Temp' will make the Temperature -widget selected by default. - -Supported widget names: -+--------------------------+ -| cpu | -+--------------------------+ -| mem, memory | -+--------------------------+ -| net, network | -+--------------------------+ -| proc, process, processes | -+--------------------------+ -| temp, temperature | -+--------------------------+ -| disk | -+--------------------------+ -| batt, battery | -+--------------------------+ -" - } - #[cfg(not(feature = "battery"))] - { - "\ -Sets which widget type to use as the default widget. -For the default layout, this defaults to the 'process' widget. -For a custom layout, it defaults to the first widget it sees. - -For example, suppose we have a layout that looks like: -+-------------------+-----------------------+ -| CPU (1) | CPU (2) | -+---------+---------+-------------+---------+ -| Process | CPU (3) | Temperature | CPU (4) | -+---------+---------+-------------+---------+ - -Setting '--default_widget_type Temp' will make the Temperature -widget selected by default. - -Supported widget names: -+--------------------------+ -| cpu | -+--------------------------+ -| mem, memory | -+--------------------------+ -| net, network | -+--------------------------+ -| proc, process, processes | -+--------------------------+ -| temp, temperature | -+--------------------------+ -| disk | -+--------------------------+ -" - } -}; +use clap::*; +use indoc::indoc; pub fn get_matches() -> ArgMatches { build_app().get_matches() @@ -175,16 +107,22 @@ fn general_args(cmd: Command) -> Command { .action(ArgAction::Set) .value_name("CONFIG PATH") .help("Sets the location of the config file.") - .long_help("Sets the location of the config file. Expects a config file in the TOML format. If it doesn't exist, one is created.") + .long_help( + "Sets the location of the config file. Expects a config file in the TOML format.\ + If it doesn't exist, one is created.", + ) .value_hint(ValueHint::AnyPath); let default_time_value = Arg::new("default_time_value") - .short('t') - .long("default_time_value") - .action(ArgAction::Set) - .value_name("TIME") - .help("Default time value for graphs.") - .long_help("Default time value for graphs. Takes a number in milliseconds or a human duration (e.g. 60s). The minimum time is 30s, and the default is 60s."); + .short('t') + .long("default_time_value") + .action(ArgAction::Set) + .value_name("TIME") + .help("Default time value for graphs.") + .long_help( + "Default time value for graphs. Takes a number in milliseconds or a human \ + duration (e.g. 60s). The minimum time is 30s, and the default is 60s.", + ); // TODO: Charts are broken in the manpage let default_widget_count = Arg::new("default_widget_count") @@ -193,39 +131,71 @@ fn general_args(cmd: Command) -> Command { .requires_all(["default_widget_type"]) .value_name("INT") .help("Sets the n'th selected widget type as the default.") - .long_help( - "\ -Sets the n'th selected widget type to use as the default widget. -Requires 'default_widget_type' to also be set, and defaults to 1. - -This reads from left to right, top to bottom. For example, suppose -we have a layout that looks like: -+-------------------+-----------------------+ -| CPU (1) | CPU (2) | -+---------+---------+-------------+---------+ -| Process | CPU (3) | Temperature | CPU (4) | -+---------+---------+-------------+---------+ - -And we set our default widget type to 'CPU'. If we set -'--default_widget_count 1', then it would use the CPU (1) as -the default widget. If we set '--default_widget_count 3', it would -use CPU (3) as the default instead. - ", - ); + .long_help(indoc! { + "Sets the n'th selected widget type to use as the default widget. + Requires 'default_widget_type' to also be set, and defaults to 1. + + This reads from left to right, top to bottom. For example, suppose + we have a layout that looks like: + +-------------------+-----------------------+ + | CPU (1) | CPU (2) | + +---------+---------+-------------+---------+ + | Process | CPU (3) | Temperature | CPU (4) | + +---------+---------+-------------+---------+ + + And we set our default widget type to 'CPU'. If we set + '--default_widget_count 1', then it would use the CPU (1) as + the default widget. If we set '--default_widget_count 3', it would + use CPU (3) as the default instead." + }); let default_widget_type = Arg::new("default_widget_type") .long("default_widget_type") .action(ArgAction::Set) .value_name("WIDGET TYPE") .help("Sets the default widget type, use --help for info.") - .long_help(DEFAULT_WIDGET_TYPE_STR); + .long_help(indoc!{ + "Sets which widget type to use as the default widget. For the default \ + layout, this defaults to the 'process' widget. For a custom layout, it defaults \ + to the first widget it sees. + + For example, suppose we have a layout that looks like: + +-------------------+-----------------------+ + | CPU (1) | CPU (2) | + +---------+---------+-------------+---------+ + | Process | CPU (3) | Temperature | CPU (4) | + +---------+---------+-------------+---------+ + + Setting '--default_widget_type Temp' will make the temperature widget selected by default." + }) + .value_parser([ + "cpu", + "mem", + "net", + "network", + "proc", + "process", + "processes", + "temp", + "temperature", + "disk", + #[cfg(not(feature = "battery"))] + "batt", + #[cfg(not(feature = "battery"))] + "battery", + ]); let expanded_on_startup = Arg::new("expanded_on_startup") .short('e') .long("expanded") .action(ArgAction::SetTrue) .help("Expand the default widget upon starting the app.") - .long_help("Expand the default widget upon starting the app. Same as pressing \"e\" inside the app. Use with \"default_widget_type\" and \"default_widget_count\" to select desired expanded widget. This flag has no effect in basic mode (--basic)."); + .long_help( + "Expand the default widget upon starting the app. \ + Same as pressing \"e\" inside the app. Use with \"default_widget_type\" \ + and \"default_widget_count\" to select the desired expanded widget. This \ + flag has no effect in basic mode (--basic).", + ); let rate = Arg::new("rate") .short('r') @@ -233,7 +203,11 @@ use CPU (3) as the default instead. .action(ArgAction::Set) .value_name("TIME") .help("Sets the data refresh rate.") - .long_help("Sets the data refresh rate. Takes a number in milliseconds or a human duration (e.g. 5s). The minimum is 250ms, and defaults to 1000ms. Smaller values may take more computer resources."); + .long_help( + "Sets the data refresh rate. Takes a number in milliseconds or a human\ + duration (e.g. 5s). The minimum is 250ms, and defaults to 1000ms. Smaller \ + values may take more computer resources.", + ); let time_delta = Arg::new("time_delta") .short('d') @@ -241,14 +215,23 @@ use CPU (3) as the default instead. .action(ArgAction::Set) .value_name("TIME") .help("The amount of time changed upon zooming.") - .long_help("The amount of time changed when zooming in/out. Takes a number in milliseconds or a human duration (e.g. 30s). The minimum is 1s, and defaults to 15s."); + .long_help( + "The amount of time changed when zooming in/out. Takes a number in \ + milliseconds or a human duration (e.g. 30s). The minimum is 1s, and \ + defaults to 15s.", + ); + // TODO: Unify how we do defaults. let retention = Arg::new("retention") .long("retention") .action(ArgAction::Set) .value_name("TIME") .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."); + .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 that higher values will take up more memory. Defaults to 10 minutes.", + ); cmd.args(args![ autohide_time, @@ -278,35 +261,28 @@ fn style_args(cmd: Command) -> Command { .long("color") .action(ArgAction::Set) .value_name("COLOR SCHEME") - .value_parser(PossibleValuesParser::new([ + .value_parser([ "default", "default-light", "gruvbox", "gruvbox-light", "nord", "nord-light", - ])) + ]) .hide_possible_values(true) - .help("Use a color scheme, use --help for info.") - .long_help( - "\ -Use a pre-defined color scheme. Currently supported values are: -+------------------------------------------------------------+ -| default | -+------------------------------------------------------------+ -| default-light (default but for use with light backgrounds) | -+------------------------------------------------------------+ -| gruvbox (a bright theme with 'retro groove' colors) | -+------------------------------------------------------------+ -| gruvbox-light (gruvbox but for use with light backgrounds) | -+------------------------------------------------------------+ -| nord (an arctic, north-bluish color palette) | -+------------------------------------------------------------+ -| nord-light (nord but for use with light backgrounds) | -+------------------------------------------------------------+ -Defaults to \"default\". - ", - ); + .help( + "Use a color scheme, use --help for info on the colors. \ + [possible values: default, default-light, gruvbox, gruvbox-light, nord, nord-light]", + ) + .long_help(indoc! { + "Use a pre-defined color scheme. Currently supported values are: + - default + - default-light (default but adjusted for lighter backgrounds) + - gruvbox (a bright theme with 'retro groove' colors) + - gruvbox-light (gruvbox but adjusted for lighter backgrounds) + - nord (an arctic, north-bluish color palette) + - nord-light (nord but adjusted for lighter backgrounds)" + }); cmd.arg(color) } @@ -358,14 +334,20 @@ fn process_args(cmd: Command) -> Command { .long("current_usage") .action(ArgAction::SetTrue) .help("Sets process CPU% to be based on current CPU%.") - .long_help("Sets process CPU% usage to be based on the current system CPU% usage rather than total CPU usage."); + .long_help( + "Sets process CPU% usage to be based on the current system CPU% usage rather \ + than total CPU usage.", + ); let unnormalized_cpu = Arg::new("unnormalized_cpu") .short('n') .long("unnormalized_cpu") .action(ArgAction::SetTrue) .help("Show process CPU% usage without normalizing over the number of cores.") - .long_help("Shows all process CPU% usage without averaging over the number of CPU cores in the system."); + .long_help( + "Shows all process CPU% usage without averaging over the number of CPU cores \ + in the system.", + ); let group_processes = Arg::new("group_processes") .short('g') @@ -391,7 +373,10 @@ fn process_args(cmd: Command) -> Command { .long("disable_advanced_kill") .action(ArgAction::SetTrue) .help("Hides advanced process killing.") - .long_help("Hides advanced options to stop a process on Unix-like systems. The only option shown is 15 (TERM)."); + .long_help( + "Hides advanced options to stop a process on Unix-like systems. The only \ + option shown is 15 (TERM).", + ); let whole_word = Arg::new("whole_word") .short('W') @@ -446,7 +431,10 @@ fn mem_args(cmd: Command) -> Command { .long("mem_as_value") .action(ArgAction::SetTrue) .help("Defaults to showing process memory usage by value.") - .long_help("Defaults to showing process memory usage by value. Otherwise, it defaults to showing it by percentage."); + .long_help( + "Defaults to showing process memory usage by value. Otherwise, it defaults \ + to showing it by percentage.", + ); #[cfg(not(target_os = "windows"))] { @@ -466,11 +454,15 @@ fn mem_args(cmd: Command) -> Command { fn network_args(cmd: Command) -> Command { let cmd = cmd.next_help_heading("Network Options"); + // TODO: Change this to be configured as network graph type? let use_old_network_legend = Arg::new("use_old_network_legend") .long("use_old_network_legend") .action(ArgAction::SetTrue) .help("DEPRECATED - uses a separate network legend.") - .long_help("DEPRECATED - uses an older (pre-0.4), separate network widget legend. This display is not tested anymore and may be broken."); + .long_help( + "DEPRECATED - uses an older (pre-0.4), separate network widget legend. This \ + display is not tested anymore and may be broken.", + ); let network_use_bytes = Arg::new("network_use_bytes") .long("network_use_bytes") @@ -488,7 +480,10 @@ fn network_args(cmd: Command) -> Command { .long("network_use_binary_prefix") .action(ArgAction::SetTrue) .help("Displays the network widget with binary prefixes.") - .long_help("Displays the network widget with binary prefixes (i.e. kibibits, mebibits) rather than a decimal prefix (i.e. kilobits, megabits). Defaults to decimal prefixes."); + .long_help( + "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![ use_old_network_legend, @@ -595,7 +590,8 @@ mod test { assert!( !help_str.to_string().contains("\nOptions:\n"), - "the default 'Options' heading should not exist; if it does then an argument is missing a help heading." + "the default 'Options' heading should not exist; if it does then an argument is \ + missing a help heading." ); } } |