deps: update clap to 3.x (#690)

Updates bottom to use clap 3.x, along with some small refactoring changes.
This commit is contained in:
Clement Tsang 2022-03-07 22:53:02 -05:00 committed by GitHub
parent e682882aee
commit 01f6bddab6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 253 additions and 295 deletions

94
Cargo.lock generated
View file

@ -26,15 +26,6 @@ dependencies = [
"memchr", "memchr",
] ]
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.44" version = "1.0.44"
@ -239,6 +230,7 @@ dependencies = [
"cargo-husky", "cargo-husky",
"cfg-if", "cfg-if",
"clap", "clap",
"clap_complete",
"crossterm", "crossterm",
"ctrlc", "ctrlc",
"dirs", "dirs",
@ -318,17 +310,28 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]] [[package]]
name = "clap" name = "clap"
version = "2.33.3" version = "3.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123"
dependencies = [ dependencies = [
"ansi_term",
"atty", "atty",
"bitflags", "bitflags",
"strsim 0.8.0", "indexmap",
"lazy_static",
"os_str_bytes",
"strsim 0.10.0",
"termcolor",
"terminal_size",
"textwrap", "textwrap",
"unicode-width", ]
"vec_map",
[[package]]
name = "clap_complete"
version = "3.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df6f3613c0a3cddfd78b41b10203eb322cb29b600cbdf808a7d3db95691b8e25"
dependencies = [
"clap",
] ]
[[package]] [[package]]
@ -1120,6 +1123,15 @@ version = "1.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0" checksum = "13bd41f508810a131401606d54ac32a467c97172d74ba7662562ebba5ad07fa0"
[[package]]
name = "os_str_bytes"
version = "6.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64"
dependencies = [
"memchr",
]
[[package]] [[package]]
name = "parking" name = "parking"
version = "2.0.0" version = "2.0.0"
@ -1424,18 +1436,18 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strsim"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
[[package]] [[package]]
name = "strsim" name = "strsim"
version = "0.9.3" version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]] [[package]]
name = "syn" name = "syn"
version = "1.0.80" version = "1.0.80"
@ -1462,6 +1474,25 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "termcolor"
version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4"
dependencies = [
"winapi-util",
]
[[package]]
name = "terminal_size"
version = "0.1.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "633c1a546cee861a1a6d0dc69ebeca693bf4296661ba7852b9d21d159e0506df"
dependencies = [
"libc",
"winapi",
]
[[package]] [[package]]
name = "termtree" name = "termtree"
version = "0.2.1" version = "0.2.1"
@ -1470,11 +1501,11 @@ checksum = "78fbf2dd23e79c28ccfa2472d3e6b3b189866ffef1aeb91f17c2d968b6586378"
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.11.0" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
dependencies = [ dependencies = [
"unicode-width", "terminal_size",
] ]
[[package]] [[package]]
@ -1582,12 +1613,6 @@ dependencies = [
"typenum", "typenum",
] ]
[[package]]
name = "vec_map"
version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
[[package]] [[package]]
name = "wait-timeout" name = "wait-timeout"
version = "0.2.0" version = "0.2.0"
@ -1640,6 +1665,15 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
dependencies = [
"winapi",
]
[[package]] [[package]]
name = "winapi-x86_64-pc-windows-gnu" name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0" version = "0.4.0"

View file

@ -40,7 +40,7 @@ anyhow = "1.0.40"
backtrace = "0.3.59" backtrace = "0.3.59"
crossterm = "0.18.2" crossterm = "0.18.2"
ctrlc = { version = "3.1.9", features = ["termination"] } ctrlc = { version = "3.1.9", features = ["termination"] }
clap = "2.33" clap = { version = "3.1.6", features = ["default", "cargo", "wrap_help"] }
cfg-if = "1.0" cfg-if = "1.0"
dirs = "4.0.0" dirs = "4.0.0"
futures = "0.3.14" futures = "0.3.14"
@ -85,13 +85,23 @@ assert_cmd = "2.0"
predicates = "2.1" predicates = "2.1"
[build-dependencies] [build-dependencies]
clap = "2.33" clap = { version = "3.1.6", features = ["default", "cargo", "wrap_help"] }
clap_complete = "3.1.1"
[package.metadata.deb] [package.metadata.deb]
section = "utility" section = "utility"
assets = [ assets = [
["target/release/btm", "usr/bin/", "755"], [
["LICENSE", "usr/share/doc/btm/", "644"], "target/release/btm",
"usr/bin/",
"755",
],
[
"LICENSE",
"usr/share/doc/btm/",
"644",
],
[ [
"completion/btm.bash", "completion/btm.bash",
"usr/share/bash-completion/completions/btm", "usr/share/bash-completion/completions/btm",
@ -102,7 +112,11 @@ assets = [
"usr/share/fish/vendor_completions.d/btm.fish", "usr/share/fish/vendor_completions.d/btm.fish",
"644", "644",
], ],
["completion/_btm", "usr/share/zsh/vendor-completions/", "644"], [
"completion/_btm",
"usr/share/zsh/vendor-completions/",
"644",
],
] ]
extended-description = """\ extended-description = """\
A customizable cross-platform graphical process/system monitor for the terminal. Supports Linux, macOS, and Windows. A customizable cross-platform graphical process/system monitor for the terminal. Supports Linux, macOS, and Windows.

View file

@ -1,5 +1,6 @@
use clap::Shell; use clap_complete::{generate_to, shells::Shell};
use std::{env, fs, process}; use std::{env, fs, process};
include!("src/clap.rs"); include!("src/clap.rs");
fn main() { fn main() {
@ -24,8 +25,9 @@ fn main() {
// Generate completions // Generate completions
let mut app = build_app(); let mut app = build_app();
app.gen_completions("btm", Shell::Bash, &out_dir); generate_to(Shell::Bash, &mut app, "btm", &out_dir).unwrap();
app.gen_completions("btm", Shell::Zsh, &out_dir); generate_to(Shell::Zsh, &mut app, "btm", &out_dir).unwrap();
app.gen_completions("btm", Shell::Fish, &out_dir); generate_to(Shell::Fish, &mut app, "btm", &out_dir).unwrap();
app.gen_completions("btm", Shell::PowerShell, &out_dir); generate_to(Shell::PowerShell, &mut app, "btm", &out_dir).unwrap();
generate_to(Shell::Elvish, &mut app, "btm", &out_dir).unwrap();
} }

View file

@ -9,7 +9,7 @@ const TEMPLATE: &str = "\
USAGE:{usage} USAGE:{usage}
FLAGS: FLAGS:
{unified}"; {options}";
const USAGE: &str = " const USAGE: &str = "
btm [FLAG]"; btm [FLAG]";
@ -46,7 +46,7 @@ Supported widget names:
+--------------------------+ +--------------------------+
| batt, battery | | batt, battery |
+--------------------------+ +--------------------------+
\n\n" "
} else { } else {
"\ "\
Sets which widget type to use as the default widget. Sets which widget type to use as the default widget.
@ -77,229 +77,171 @@ Supported widget names:
+--------------------------+ +--------------------------+
| disk | | disk |
+--------------------------+ +--------------------------+
\n\n" "
}; };
pub fn get_matches() -> clap::ArgMatches<'static> { pub fn get_matches() -> clap::ArgMatches {
build_app().get_matches() build_app().get_matches()
} }
// TODO: Refactor this a bit, it's quite messy atm // TODO: Refactor this a bit, it's quite messy atm
pub fn build_app() -> App<'static, 'static> { pub fn build_app() -> Command<'static> {
// Temps // Temps
let kelvin = Arg::with_name("kelvin") let kelvin = Arg::new("kelvin")
.short("k") .short('k')
.long("kelvin") .long("kelvin")
.help("Sets the temperature type to Kelvin.") .help("Sets the temperature type to Kelvin.")
.long_help( .long_help("Sets the temperature type to Kelvin.");
"\
Sets the temperature type to Kelvin.\n\n", let fahrenheit = Arg::new("fahrenheit")
); .short('f')
let fahrenheit = Arg::with_name("fahrenheit")
.short("f")
.long("fahrenheit") .long("fahrenheit")
.help("Sets the temperature type to Fahrenheit.") .help("Sets the temperature type to Fahrenheit.")
.long_help( .long_help("Sets the temperature type to Fahrenheit.");
"\
Sets the temperature type to Fahrenheit.\n\n", let celsius = Arg::new("celsius")
); .short('c')
let celsius = Arg::with_name("celsius")
.short("c")
.long("celsius") .long("celsius")
.help("Sets the temperature type to Celsius.") .help("Sets the temperature type to Celsius.")
.long_help( .long_help("Sets the temperature type to Celsius. This is the default option.");
"\
Sets the temperature type to Celsius. This is the default
option.\n\n",
);
// All flags. These are in alphabetical order // All flags. These are in alphabetical order
let autohide_time = Arg::with_name("autohide_time") let autohide_time = Arg::new("autohide_time")
.long("autohide_time") .long("autohide_time")
.help("Temporarily shows the time scale in graphs.") .help("Temporarily shows the time scale in graphs.")
.long_help( .long_help(
"\ "Automatically hides the time scale in graphs after being shown for \
Automatically hides the time scale in graphs after being a brief moment when zoomed in/out. If time is disabled via --hide_time \
shown for a brief moment when zoomed in/out. If time is then this will have no effect.",
disabled via --hide_time then this will have no effect.\n\n\n",
); );
let basic = Arg::with_name("basic")
.short("b") let basic = Arg::new("basic")
.short('b')
.long("basic") .long("basic")
.help("Hides graphs and uses a more basic look.") .help("Hides graphs and uses a more basic look.")
.long_help( .long_help(
"\ "Hides graphs and uses a more basic look. Design is largely inspired by htop's.",
Hides graphs and uses a more basic look. Design is largely
inspired by htop's.\n\n",
); );
let case_sensitive = Arg::with_name("case_sensitive")
.short("S") let case_sensitive = Arg::new("case_sensitive")
.short('S')
.long("case_sensitive") .long("case_sensitive")
.help("Enables case sensitivity by default.") .help("Enables case sensitivity by default.")
.long_help( .long_help("When searching for a process, enables case sensitivity by default.");
"\
When searching for a process, enables case sensitivity by default.\n\n", let current_usage = Arg::new("current_usage")
); .short('u')
let current_usage = Arg::with_name("current_usage")
.short("u")
.long("current_usage") .long("current_usage")
.help("Sets process CPU% to be based on current CPU%.") .help("Sets process CPU% to be based on current CPU%.")
.long_help( .long_help("Sets process CPU% usage to be based on the current system CPU% usage rather than total CPU usage.");
"\
Sets process CPU% usage to be based on the current system CPU% usage
rather than total CPU usage.\n\n",
);
// TODO: [DEBUG] Add a proper debugging solution. // TODO: [DEBUG] Add a proper debugging solution.
// let debug = Arg::with_name("debug")
// .long("debug") let disable_click = Arg::new("disable_click")
// .help("Enables debug logging.")
// .long_help(
// "\
// Enables debug logging. The program will print where it logged to after running.",
// );
// TODO: [DIAGNOSE] Add a diagnose option to help with debugging.
let disable_click = Arg::with_name("disable_click")
.long("disable_click") .long("disable_click")
.help("Disables mouse clicks.") .help("Disables mouse clicks.")
.long_help( .long_help("Disables mouse clicks from interacting with the program.");
"\
Disables mouse clicks from interacting with the program.\n\n",
);
let dot_marker = Arg::with_name("dot_marker") let dot_marker = Arg::new("dot_marker")
.short("m") .short('m')
.long("dot_marker") .long("dot_marker")
.help("Uses a dot marker for graphs.") .help("Uses a dot marker for graphs.")
.long_help( .long_help("Uses a dot marker for graphs as opposed to the default braille marker.");
"\
Uses a dot marker for graphs as opposed to the default braille
marker.\n\n",
);
let group = Arg::with_name("group") // FIXME: Rename this to something like "group_process", would be "breaking" though. let group = Arg::new("group") // FIXME: Rename this to something like "group_process", would be "breaking" though.
.short("g") .short('g')
.long("group") .long("group")
.help("Groups processes with the same name by default.") .help("Groups processes with the same name by default.")
.long_help( .long_help("Groups processes with the same name by default.");
"\
Groups processes with the same name by default.\n\n",
);
let hide_avg_cpu = Arg::with_name("hide_avg_cpu") let hide_avg_cpu = Arg::new("hide_avg_cpu")
.short("a") .short('a')
.long("hide_avg_cpu") .long("hide_avg_cpu")
.help("Hides the average CPU usage.") .help("Hides the average CPU usage.")
.long_help( .long_help("Hides the average CPU usage from being shown.");
"\
Hides the average CPU usage from being shown.\n\n",
);
let hide_table_gap = Arg::with_name("hide_table_gap") let hide_table_gap = Arg::new("hide_table_gap")
.long("hide_table_gap") .long("hide_table_gap")
.help("Hides the spacing between table headers and entries.") .help("Hides the spacing between table headers and entries.")
.long_help( .long_help("Hides the spacing between table headers and entries.");
"\
Hides the spacing between table headers and entries.\n\n",
);
let hide_time = Arg::with_name("hide_time") let hide_time = Arg::new("hide_time")
.long("hide_time") .long("hide_time")
.help("Hides the time scale.") .help("Hides the time scale.")
.long_help( .long_help("Completely hides the time scale from being shown.");
"\
Completely hides the time scale from being shown.\n\n",
);
let process_command = Arg::with_name("process_command") let process_command = Arg::new("process_command")
.long("process_command") .long("process_command")
.help("Show processes as their commands by default.") .help("Show processes as their commands by default.")
.long_help( .long_help("Show processes as their commands by default in the process widget.");
"\
Show processes as their commands by default in the process widget.
",
);
let left_legend = Arg::with_name("left_legend") let left_legend = Arg::new("left_legend")
.short("l") .short('l')
.long("left_legend") .long("left_legend")
.help("Puts the CPU chart legend to the left side.") .help("Puts the CPU chart legend to the left side.")
.long_help( .long_help("Puts the CPU chart legend to the left side rather than the right side.");
"\
Puts the CPU chart legend to the left side rather than the right side.\n\n",
);
// let no_write = Arg::with_name("no_write") let regex = Arg::new("regex")
// .long("no_write") .short('R')
// .help("Disables writing to the config file.")
// .long_help(
// "\
// Disables config changes in-app from writing to the config file.",
// );
let regex = Arg::with_name("regex")
.short("R")
.long("regex") .long("regex")
.help("Enables regex by default.") .help("Enables regex by default.")
.long_help( .long_help("When searching for a process, enables regex by default.");
"\
When searching for a process, enables regex by default.\n\n",
);
let disable_advanced_kill = Arg::with_name("disable_advanced_kill") let disable_advanced_kill = Arg::new("disable_advanced_kill")
.long("disable_advanced_kill") .long("disable_advanced_kill")
.help("Hides advanced options to stop a process on Unix-like systems.") .help("Hides advanced options to stop a process on Unix-like systems.")
.long_help( .long_help("Hides advanced options to stop a process on Unix-like systems. The only option shown is -15.");
"\
Hides advanced options to stop a process on Unix-like systems. The only option shown is -15.\n\n",
);
let show_table_scroll_position = Arg::with_name("show_table_scroll_position") let show_table_scroll_position = Arg::new("show_table_scroll_position")
.long("show_table_scroll_position") .long("show_table_scroll_position")
.help("Shows the scroll position tracker in table widgets.") .help("Shows the scroll position tracker in table widgets.")
.long_help( .long_help("Shows the list scroll position tracker in the widget title for table widgets.");
"\
Shows the list scroll position tracker in the widget title for table widgets.\n\n",
);
let use_old_network_legend = Arg::with_name("use_old_network_legend") let use_old_network_legend = Arg::new("use_old_network_legend")
.long("use_old_network_legend") .long("use_old_network_legend")
.help("DEPRECATED - uses the older network legend.") .help("DEPRECATED - uses a separate network legend.")
.long_help( .long_help(
"\ "DEPRECATED - uses an older (pre-0.4), separate network widget legend. This display is not \
DEPRECATED - uses the older (pre-0.4) network widget legend. tested anymore and could be broken.",
This display is not tested anymore and could be broken.\n\n\n",
); );
let whole_word = Arg::with_name("whole_word") let whole_word = Arg::new("whole_word")
.short("W") .short('W')
.long("whole_word") .long("whole_word")
.help("Enables whole-word matching by default.") .help("Enables whole-word matching by default.")
.long_help( .long_help(
"\ "When searching for a process, return results that match the entire query by default.",
When searching for a process, return results that match the
entire query by default.\n\n",
); );
// All options. Again, alphabetical order. // All options. Again, alphabetical order.
let config_location = Arg::with_name("config_location") let config_location = Arg::new("config_location")
.short("C") .short('C')
.long("config") .long("config")
.takes_value(true) .takes_value(true)
.value_name("CONFIG PATH") .value_name("CONFIG PATH")
.help("Sets the location of the config file.") .help("Sets the location of the config file.")
.long_help( .long_help(
"\ "Sets the location of the config file. Expects a config file in the TOML format. \
Sets the location of the config file. Expects a config If it doesn't exist, one is created.",
file in the TOML format. If it doesn't exist, one is created.\n\n\n",
); );
let color = Arg::with_name("color")
let color = Arg::new("color")
.long("color") .long("color")
.takes_value(true) .takes_value(true)
.value_name("COLOR SCHEME") .value_name("COLOR SCHEME")
.possible_values(&[
"default",
"default-light",
"gruvbox",
"gruvbox-light",
"nord",
"nord-light",
])
.hide_possible_values(true)
.help("Use a color scheme, use --help for supported values.") .help("Use a color scheme, use --help for supported values.")
.long_help( .long_help(
"\ "\
Use a pre-defined color scheme. Currently supported values are: Use a pre-defined color scheme. Currently supported values are:
+------------------------------------------------------------+ +------------------------------------------------------------+
| default | | default |
@ -316,37 +258,23 @@ Use a pre-defined color scheme. Currently supported values are:
+------------------------------------------------------------+ +------------------------------------------------------------+
Defaults to \"default\". Defaults to \"default\".
\n\n", ",
) );
.possible_values(&[
"default", let mem_as_value = Arg::new("mem_as_value")
"default-light",
"gruvbox",
"gruvbox-light",
"nord",
"nord-light",
])
.hide_possible_values(true);
let mem_as_value = Arg::with_name("mem_as_value")
.long("mem_as_value") .long("mem_as_value")
.help("Defaults to showing process memory usage by value.") .help("Defaults to showing process memory usage by value.")
.long_help( .long_help("Defaults to showing process memory usage by value. Otherwise, it defaults to showing it by percentage.");
"\
Defaults to showing process memory usage by value. Otherwise, let default_time_value = Arg::new("default_time_value")
it defaults to showing it by percentage.\n\n", .short('t')
);
let default_time_value = Arg::with_name("default_time_value")
.short("t")
.long("default_time_value") .long("default_time_value")
.takes_value(true) .takes_value(true)
.value_name("MS") .value_name("MS")
.help("Default time value for graphs in ms.") .help("Default time value for graphs in ms.")
.long_help( .long_help("Default time value for graphs in milliseconds. The minimum time is 30s (30000), and the default is 60s (60000).");
"\
Default time value for graphs in milliseconds. The minimum let default_widget_count = Arg::new("default_widget_count")
time is 30s (30000), and the default is 60s (60000).\n\n\n",
);
let default_widget_count = Arg::with_name("default_widget_count")
.long("default_widget_count") .long("default_widget_count")
.takes_value(true) .takes_value(true)
.requires_all(&["default_widget_type"]) .requires_all(&["default_widget_type"])
@ -357,7 +285,7 @@ time is 30s (30000), and the default is 60s (60000).\n\n\n",
Sets the n'th selected widget type to use as the default widget. 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. Requires 'default_widget_type' to also be set, and defaults to 1.
This reads from left to right, top to bottom. For example, suppose This reads from left to right, top to bottom. For example, suppose
we have a layout that looks like: we have a layout that looks like:
+-------------------+-----------------------+ +-------------------+-----------------------+
| CPU (1) | CPU (2) | | CPU (1) | CPU (2) |
@ -365,87 +293,73 @@ we have a layout that looks like:
| Process | CPU (3) | Temperature | CPU (4) | | Process | CPU (3) | Temperature | CPU (4) |
+---------+---------+-------------+---------+ +---------+---------+-------------+---------+
And we set our default widget type to 'CPU'. If we set And we set our default widget type to 'CPU'. If we set
'--default_widget_count 1', then it would use the CPU (1) as '--default_widget_count 1', then it would use the CPU (1) as
the default widget. If we set '--default_widget_count 3', it would the default widget. If we set '--default_widget_count 3', it would
use CPU (3) as the default instead. use CPU (3) as the default instead.
\n\n", ",
); );
let default_widget_type = Arg::with_name("default_widget_type")
let default_widget_type = Arg::new("default_widget_type")
.long("default_widget_type") .long("default_widget_type")
.takes_value(true) .takes_value(true)
.value_name("WIDGET TYPE") .value_name("WIDGET TYPE")
.help("Sets the default widget type, use --help for more info.") .help("Sets the default widget type, use --help for more info.")
.long_help(DEFAULT_WIDGET_TYPE_STR); .long_help(DEFAULT_WIDGET_TYPE_STR);
let rate = Arg::with_name("rate")
.short("r") let rate = Arg::new("rate")
.short('r')
.long("rate") .long("rate")
.takes_value(true) .takes_value(true)
.value_name("MS") .value_name("MS")
.help("Sets a refresh rate in ms.") .help("Sets a refresh rate in ms.")
.long_help( .long_help("Sets a refresh rate in milliseconds. The minimum is 250ms, and defaults to 1000ms. Smaller values may take more computer resources.");
"\
Sets a refresh rate in milliseconds. The minimum is 250ms, let time_delta = Arg::new("time_delta")
and defaults to 1000ms. Smaller values may take more resources.\n\n\n", .short('d')
);
let time_delta = Arg::with_name("time_delta")
.short("d")
.long("time_delta") .long("time_delta")
.takes_value(true) .takes_value(true)
.value_name("MS") .value_name("MS")
.help("The amount in ms changed upon zooming.") .help("The amount in ms changed upon zooming.")
.long_help( .long_help("The amount of time in milliseconds changed when zooming in/out. The minimum is 1s (1000), and defaults to 15s (15000).");
"\
The amount of time in milliseconds changed when zooming in/out.
The minimum is 1s (1000), and defaults to 15s (15000).\n\n\n",
);
let tree = Arg::with_name("tree") let tree = Arg::new("tree")
.short("T") .short('T')
.long("tree") .long("tree")
.help("Defaults to showing the process widget in tree mode.") .help("Defaults to showing the process widget in tree mode.")
.long_help( .long_help("Defaults to showing the process widget in tree mode.");
"\
Defaults to showing the process widget in tree mode.\n\n",
);
let network_use_bytes = Arg::with_name("network_use_bytes") let network_use_bytes = Arg::new("network_use_bytes")
.long("network_use_bytes") .long("network_use_bytes")
.help("Displays the network widget using bytes.") .help("Displays the network widget using bytes.")
.long_help( .long_help("Displays the network widget using bytes. Defaults to bits.");
"\
Displays the network widget using bytes. Defaults to bits.\n\n",
);
let network_use_log = Arg::with_name("network_use_log") let network_use_log = Arg::new("network_use_log")
.long("network_use_log") .long("network_use_log")
.help("Displays the network widget with a log scale.") .help("Displays the network widget with a log scale.")
.long_help( .long_help("Displays the network widget with a log scale. Defaults to a non-log scale.");
"\
Displays the network widget with a log scale. Defaults to a non-log scale.\n\n",
);
let network_use_binary_prefix = Arg::with_name("network_use_binary_prefix") let network_use_binary_prefix = Arg::new("network_use_binary_prefix")
.long("network_use_binary_prefix") .long("network_use_binary_prefix")
.help("Displays the network widget with binary prefixes.") .help("Displays the network widget with binary prefixes.")
.long_help( .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.",
Displays the network widget with binary prefixes (i.e. kibibits, mebibits) rather than a decimal prefix (i.e. kilobits, megabits). Defaults to decimal prefixes.\n\n\n",
); );
let app = App::new(crate_name!()) let app = Command::new(crate_name!())
.setting(AppSettings::UnifiedHelpMessage)
.version(crate_version!()) .version(crate_version!())
.author(crate_authors!()) .author(crate_authors!())
.about(crate_description!()) .about(crate_description!())
.template(TEMPLATE) .override_usage(USAGE)
.usage(USAGE) .help_template(TEMPLATE)
.help_message("Prints help information. Use --help for more info.") .mut_arg("help", |a| {
.version_message("Prints version information.") a.help("Prints help information. Use --help for more info.")
})
.mut_arg("version", |a| a.help("Prints version information."))
.arg(kelvin) .arg(kelvin)
.arg(fahrenheit) .arg(fahrenheit)
.arg(celsius) .arg(celsius)
.group(ArgGroup::with_name("TEMPERATURE_TYPE").args(&["kelvin", "fahrenheit", "celsius"])) .group(ArgGroup::new("TEMPERATURE_TYPE").args(&["kelvin", "fahrenheit", "celsius"]))
.arg(autohide_time) .arg(autohide_time)
.arg(basic) .arg(basic)
.arg(case_sensitive) .arg(case_sensitive)
@ -477,13 +391,11 @@ Displays the network widget with binary prefixes (i.e. kibibits, mebibits) rathe
.arg(whole_word); .arg(whole_word);
let app = if cfg!(feature = "battery") { let app = if cfg!(feature = "battery") {
let battery = Arg::with_name("battery") let battery = Arg::new("battery")
.long("battery") .long("battery")
.help("Shows the battery widget.") .help("Shows the battery widget.")
.long_help( .long_help(
"\ "Shows the battery widget in default or basic mode. No effect on custom layouts.",
Shows the battery widget in default or basic mode. No effect on
custom layouts.\n\n",
); );
app.arg(battery) app.arg(battery)
} else { } else {

View file

@ -244,7 +244,7 @@ pub struct IgnoreList {
} }
pub fn build_app( pub fn build_app(
matches: &clap::ArgMatches<'static>, config: &mut Config, widget_layout: &BottomLayout, matches: &clap::ArgMatches, config: &mut Config, widget_layout: &BottomLayout,
default_widget_id: u64, default_widget_type_option: &Option<BottomWidgetType>, default_widget_id: u64, default_widget_type_option: &Option<BottomWidgetType>,
config_path: Option<PathBuf>, config_path: Option<PathBuf>,
) -> Result<App> { ) -> Result<App> {
@ -524,7 +524,7 @@ pub fn build_app(
} }
pub fn get_widget_layout( pub fn get_widget_layout(
matches: &clap::ArgMatches<'static>, config: &Config, matches: &clap::ArgMatches, config: &Config,
) -> error::Result<(BottomLayout, u64, Option<BottomWidgetType>)> { ) -> error::Result<(BottomLayout, u64, Option<BottomWidgetType>)> {
let left_legend = get_use_left_legend(matches, config); let left_legend = get_use_left_legend(matches, config);
let (default_widget_type, mut default_widget_count) = let (default_widget_type, mut default_widget_count) =
@ -589,7 +589,7 @@ pub fn get_widget_layout(
} }
fn get_update_rate_in_milliseconds( fn get_update_rate_in_milliseconds(
matches: &clap::ArgMatches<'static>, config: &Config, matches: &clap::ArgMatches, config: &Config,
) -> error::Result<u64> { ) -> error::Result<u64> {
let update_rate_in_milliseconds = if let Some(update_rate) = matches.value_of("rate") { let update_rate_in_milliseconds = if let Some(update_rate) = matches.value_of("rate") {
update_rate.parse::<u128>()? update_rate.parse::<u128>()?
@ -617,7 +617,7 @@ fn get_update_rate_in_milliseconds(
} }
fn get_temperature( fn get_temperature(
matches: &clap::ArgMatches<'static>, config: &Config, matches: &clap::ArgMatches, config: &Config,
) -> error::Result<data_harvester::temperature::TemperatureType> { ) -> error::Result<data_harvester::temperature::TemperatureType> {
if matches.is_present("fahrenheit") { if matches.is_present("fahrenheit") {
return Ok(data_harvester::temperature::TemperatureType::Fahrenheit); return Ok(data_harvester::temperature::TemperatureType::Fahrenheit);
@ -643,7 +643,7 @@ fn get_temperature(
} }
/// Yes, this function gets whether to show average CPU (true) or not (false) /// Yes, this function gets whether to show average CPU (true) or not (false)
fn get_show_average_cpu(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_show_average_cpu(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("hide_avg_cpu") { if matches.is_present("hide_avg_cpu") {
return false; return false;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -655,7 +655,7 @@ fn get_show_average_cpu(matches: &clap::ArgMatches<'static>, config: &Config) ->
true true
} }
fn get_use_dot(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_use_dot(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("dot_marker") { if matches.is_present("dot_marker") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -666,7 +666,7 @@ fn get_use_dot(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
false false
} }
fn get_use_left_legend(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_use_left_legend(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("left_legend") { if matches.is_present("left_legend") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -678,7 +678,7 @@ fn get_use_left_legend(matches: &clap::ArgMatches<'static>, config: &Config) ->
false false
} }
fn get_use_current_cpu_total(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_use_current_cpu_total(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("current_usage") { if matches.is_present("current_usage") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -690,7 +690,7 @@ fn get_use_current_cpu_total(matches: &clap::ArgMatches<'static>, config: &Confi
false false
} }
fn get_use_basic_mode(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_use_basic_mode(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("basic") { if matches.is_present("basic") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -702,9 +702,7 @@ fn get_use_basic_mode(matches: &clap::ArgMatches<'static>, config: &Config) -> b
false false
} }
fn get_default_time_value( fn get_default_time_value(matches: &clap::ArgMatches, config: &Config) -> error::Result<u64> {
matches: &clap::ArgMatches<'static>, config: &Config,
) -> error::Result<u64> {
let default_time = if let Some(default_time_value) = matches.value_of("default_time_value") { let default_time = if let Some(default_time_value) = matches.value_of("default_time_value") {
default_time_value.parse::<u128>()? default_time_value.parse::<u128>()?
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -731,7 +729,7 @@ fn get_default_time_value(
Ok(default_time as u64) Ok(default_time as u64)
} }
fn get_time_interval(matches: &clap::ArgMatches<'static>, config: &Config) -> error::Result<u64> { fn get_time_interval(matches: &clap::ArgMatches, config: &Config) -> error::Result<u64> {
let time_interval = if let Some(time_interval) = matches.value_of("time_delta") { let time_interval = if let Some(time_interval) = matches.value_of("time_delta") {
time_interval.parse::<u128>()? time_interval.parse::<u128>()?
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -758,7 +756,7 @@ fn get_time_interval(matches: &clap::ArgMatches<'static>, config: &Config) -> er
Ok(time_interval as u64) Ok(time_interval as u64)
} }
pub fn get_app_grouping(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { pub fn get_app_grouping(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("group") { if matches.is_present("group") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -769,7 +767,7 @@ pub fn get_app_grouping(matches: &clap::ArgMatches<'static>, config: &Config) ->
false false
} }
pub fn get_app_case_sensitive(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { pub fn get_app_case_sensitive(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("case_sensitive") { if matches.is_present("case_sensitive") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -780,7 +778,7 @@ pub fn get_app_case_sensitive(matches: &clap::ArgMatches<'static>, config: &Conf
false false
} }
pub fn get_app_match_whole_word(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { pub fn get_app_match_whole_word(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("whole_word") { if matches.is_present("whole_word") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -791,7 +789,7 @@ pub fn get_app_match_whole_word(matches: &clap::ArgMatches<'static>, config: &Co
false false
} }
pub fn get_app_use_regex(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { pub fn get_app_use_regex(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("regex") { if matches.is_present("regex") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -802,7 +800,7 @@ pub fn get_app_use_regex(matches: &clap::ArgMatches<'static>, config: &Config) -
false false
} }
fn get_hide_time(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_hide_time(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("hide_time") { if matches.is_present("hide_time") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -813,7 +811,7 @@ fn get_hide_time(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
false false
} }
fn get_autohide_time(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_autohide_time(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("autohide_time") { if matches.is_present("autohide_time") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -826,7 +824,7 @@ fn get_autohide_time(matches: &clap::ArgMatches<'static>, config: &Config) -> bo
} }
fn get_default_widget_and_count( fn get_default_widget_and_count(
matches: &clap::ArgMatches<'static>, config: &Config, matches: &clap::ArgMatches, config: &Config,
) -> error::Result<(Option<BottomWidgetType>, u64)> { ) -> error::Result<(Option<BottomWidgetType>, u64)> {
let widget_type = if let Some(widget_type) = matches.value_of("default_widget_type") { let widget_type = if let Some(widget_type) = matches.value_of("default_widget_type") {
let parsed_widget = widget_type.parse::<BottomWidgetType>()?; let parsed_widget = widget_type.parse::<BottomWidgetType>()?;
@ -878,7 +876,7 @@ fn get_default_widget_and_count(
} }
} }
fn get_disable_click(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_disable_click(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("disable_click") { if matches.is_present("disable_click") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -889,7 +887,7 @@ fn get_disable_click(matches: &clap::ArgMatches<'static>, config: &Config) -> bo
false false
} }
fn get_use_old_network_legend(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_use_old_network_legend(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("use_old_network_legend") { if matches.is_present("use_old_network_legend") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -900,7 +898,7 @@ fn get_use_old_network_legend(matches: &clap::ArgMatches<'static>, config: &Conf
false false
} }
fn get_hide_table_gap(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_hide_table_gap(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("hide_table_gap") { if matches.is_present("hide_table_gap") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -911,7 +909,7 @@ fn get_hide_table_gap(matches: &clap::ArgMatches<'static>, config: &Config) -> b
false false
} }
fn get_use_battery(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_use_battery(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("battery") { if matches.is_present("battery") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -923,7 +921,7 @@ fn get_use_battery(matches: &clap::ArgMatches<'static>, config: &Config) -> bool
} }
#[allow(dead_code)] #[allow(dead_code)]
fn get_no_write(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_no_write(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("no_write") { if matches.is_present("no_write") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -972,7 +970,7 @@ fn get_ignore_list(ignore_list: &Option<IgnoreList>) -> error::Result<Option<Fil
} }
pub fn get_color_scheme( pub fn get_color_scheme(
matches: &clap::ArgMatches<'static>, config: &Config, matches: &clap::ArgMatches, config: &Config,
) -> error::Result<ColourScheme> { ) -> error::Result<ColourScheme> {
if let Some(color) = matches.value_of("color") { if let Some(color) = matches.value_of("color") {
// Highest priority is always command line flags... // Highest priority is always command line flags...
@ -998,7 +996,7 @@ pub fn get_color_scheme(
Ok(ColourScheme::Default) Ok(ColourScheme::Default)
} }
fn get_mem_as_value(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_mem_as_value(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("mem_as_value") { if matches.is_present("mem_as_value") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -1009,7 +1007,7 @@ fn get_mem_as_value(matches: &clap::ArgMatches<'static>, config: &Config) -> boo
false false
} }
fn get_is_default_tree(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_is_default_tree(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("tree") { if matches.is_present("tree") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -1020,7 +1018,7 @@ fn get_is_default_tree(matches: &clap::ArgMatches<'static>, config: &Config) ->
false false
} }
fn get_show_table_scroll_position(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_show_table_scroll_position(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("show_table_scroll_position") { if matches.is_present("show_table_scroll_position") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -1031,7 +1029,7 @@ fn get_show_table_scroll_position(matches: &clap::ArgMatches<'static>, config: &
false false
} }
fn get_is_default_process_command(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_is_default_process_command(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("process_command") { if matches.is_present("process_command") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -1042,7 +1040,7 @@ fn get_is_default_process_command(matches: &clap::ArgMatches<'static>, config: &
false false
} }
fn get_is_advanced_kill_disabled(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_is_advanced_kill_disabled(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("disable_advanced_kill") { if matches.is_present("disable_advanced_kill") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -1053,7 +1051,7 @@ fn get_is_advanced_kill_disabled(matches: &clap::ArgMatches<'static>, config: &C
false false
} }
fn get_network_unit_type(matches: &clap::ArgMatches<'static>, config: &Config) -> DataUnit { fn get_network_unit_type(matches: &clap::ArgMatches, config: &Config) -> DataUnit {
if matches.is_present("network_use_bytes") { if matches.is_present("network_use_bytes") {
return DataUnit::Byte; return DataUnit::Byte;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -1067,7 +1065,7 @@ fn get_network_unit_type(matches: &clap::ArgMatches<'static>, config: &Config) -
DataUnit::Bit DataUnit::Bit
} }
fn get_network_scale_type(matches: &clap::ArgMatches<'static>, config: &Config) -> AxisScaling { fn get_network_scale_type(matches: &clap::ArgMatches, config: &Config) -> AxisScaling {
if matches.is_present("network_use_log") { if matches.is_present("network_use_log") {
return AxisScaling::Log; return AxisScaling::Log;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {
@ -1081,7 +1079,7 @@ fn get_network_scale_type(matches: &clap::ArgMatches<'static>, config: &Config)
AxisScaling::Linear AxisScaling::Linear
} }
fn get_network_use_binary_prefix(matches: &clap::ArgMatches<'static>, config: &Config) -> bool { fn get_network_use_binary_prefix(matches: &clap::ArgMatches, config: &Config) -> bool {
if matches.is_present("network_use_binary_prefix") { if matches.is_present("network_use_binary_prefix") {
return true; return true;
} else if let Some(flags) = &config.flags { } else if let Some(flags) = &config.flags {

View file

@ -130,9 +130,7 @@ fn test_conflicting_temps() {
.arg("-f") .arg("-f")
.assert() .assert()
.failure() .failure()
.stderr(predicate::str::contains( .stderr(predicate::str::contains("cannot be used with"));
"cannot be used with one or more of the other specified arguments",
));
} }
#[test] #[test]