summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Cargo.lock90
-rw-r--r--Cargo.toml24
-rw-r--r--build.rs12
-rw-r--r--src/clap.rs348
-rw-r--r--src/options.rs66
-rw-r--r--tests/arg_tests.rs4
6 files changed, 251 insertions, 293 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 4ecf0146..72534a71 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -27,15 +27,6 @@ dependencies = [
]
[[package]]
-name = "ansi_term"
-version = "0.11.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
-dependencies = [
- "winapi",
-]
-
-[[package]]
name = "anyhow"
version = "1.0.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -239,6 +230,7 @@ dependencies = [
"cargo-husky",
"cfg-if",
"clap",
+ "clap_complete",
"crossterm",
"ctrlc",
"dirs",
@@ -318,17 +310,28 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
-version = "2.33.3"
+version = "3.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
+checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123"
dependencies = [
- "ansi_term",
"atty",
"bitflags",
- "strsim 0.8.0",
+ "indexmap",
+ "lazy_static",
+ "os_str_bytes",
+ "strsim 0.10.0",
+ "termcolor",
+ "terminal_size",
"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]]
@@ -1121,6 +1124,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "parking"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1426,15 +1438,15 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "strsim"
-version = "0.8.0"
+version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a"
+checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
[[package]]
name = "strsim"
-version = "0.9.3"
+version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
+checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
@@ -1463,6 +1475,25 @@ dependencies = [
]
[[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]]
name = "termtree"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1470,11 +1501,11 @@ checksum = "78fbf2dd23e79c28ccfa2472d3e6b3b189866ffef1aeb91f17c2d968b6586378"
[[package]]
name = "textwrap"
-version = "0.11.0"
+version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060"
+checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
dependencies = [
- "unicode-width",
+ "terminal_size",
]
[[package]]
@@ -1583,12 +1614,6 @@ dependencies = [
]
[[package]]
-name = "vec_map"
-version = "0.8.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191"
-
-[[package]]
name = "wait-timeout"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1641,6 +1666,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
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]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 5c8e6e56..97572b7c 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -40,7 +40,7 @@ anyhow = "1.0.40"
backtrace = "0.3.59"
crossterm = "0.18.2"
ctrlc = { version = "3.1.9", features = ["termination"] }
-clap = "2.33"
+clap = { version = "3.1.6", features = ["default", "cargo", "wrap_help"] }
cfg-if = "1.0"
dirs = "4.0.0"
futures = "0.3.14"
@@ -85,13 +85,23 @@ assert_cmd = "2.0"
predicates = "2.1"
[build-dependencies]
-clap = "2.33"
+clap = { version = "3.1.6", features = ["default", "cargo", "wrap_help"] }
+clap_complete = "3.1.1"
+
[package.metadata.deb]
section = "utility"
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",
"usr/share/bash-completion/completions/btm",
@@ -102,7 +112,11 @@ assets = [
"usr/share/fish/vendor_completions.d/btm.fish",
"644",
],
- ["completion/_btm", "usr/share/zsh/vendor-completions/", "644"],
+ [
+ "completion/_btm",
+ "usr/share/zsh/vendor-completions/",
+ "644",
+ ],
]
extended-description = """\
A customizable cross-platform graphical process/system monitor for the terminal. Supports Linux, macOS, and Windows.
diff --git a/build.rs b/build.rs
index 472a0a6c..479ab963 100644
--- a/build.rs
+++ b/build.rs
@@ -1,5 +1,6 @@
-use clap::Shell;
+use clap_complete::{generate_to, shells::Shell};
use std::{env, fs, process};
+
include!("src/clap.rs");
fn main() {
@@ -24,8 +25,9 @@ fn main() {
// Generate completions
let mut app = build_app();
- app.gen_completions("btm", Shell::Bash, &out_dir);
- app.gen_completions("btm", Shell::Zsh, &out_dir);
- app.gen_completions("btm", Shell::Fish, &out_dir);
- app.gen_completions("btm", Shell::PowerShell, &out_dir);
+ generate_to(Shell::Bash, &mut app, "btm", &out_dir).unwrap();
+ generate_to(Shell::Zsh, &mut app, "btm", &out_dir).unwrap();
+ generate_to(Shell::Fish, &mut app, "btm", &out_dir).unwrap();
+ generate_to(Shell::PowerShell, &mut app, "btm", &out_dir).unwrap();
+ generate_to(Shell::Elvish, &mut app, "btm", &out_dir).unwrap();
}
diff --git a/src/clap.rs b/src/clap.rs
index 8604c5a8..282b79b2 100644
--- a/src/clap.rs
+++ b/src/clap.rs
@@ -9,7 +9,7 @@ const TEMPLATE: &str = "\
USAGE:{usage}
FLAGS:
-{unified}";
+{options}";
const USAGE: &str = "
btm [FLAG]";
@@ -46,7 +46,7 @@ Supported widget names:
+--------------------------+
| batt, battery |
+--------------------------+
-\n\n"
+"
} else {
"\
Sets which widget type to use as the default widget.
@@ -77,229 +77,171 @@ Supported widget names:
+--------------------------+
| disk |
+--------------------------+
-\n\n"
+"
};
-pub fn get_matches() -> clap::ArgMatches<'static> {
+pub fn get_matches() -> clap::ArgMatches {
build_app().get_matches()
}
// TODO: Refactor this a bit, it's quite messy atm
-pub fn build_app() -> App<'static, 'static> {
+pub fn build_app() -> Command<'static> {
// Temps
- let kelvin = Arg::with_name("kelvin")
- .short("k")
+ let kelvin = Arg::new("kelvin")
+ .short('k')
.long("kelvin")
.help("Sets the temperature type to Kelvin.")
- .long_help(
- "\
-Sets the temperature type to Kelvin.\n\n",
- );
- let fahrenheit = Arg::with_name("fahrenheit")
- .short("f")
+ .long_help("Sets the temperature type to Kelvin.");
+
+ let fahrenheit = Arg::new("fahrenheit")
+ .short('f')
.long("fahrenheit")
.help("Sets the temperature type to Fahrenheit.")
- .long_help(
- "\
-Sets the temperature type to Fahrenheit.\n\n",
- );
- let celsius = Arg::with_name("celsius")
- .short("c")
+ .long_help("Sets the temperature type to Fahrenheit.");
+
+ let celsius = Arg::new("celsius")
+ .short('c')
.long("celsius")
.help("Sets the temperature type to Celsius.")
- .long_help(
- "\
-Sets the temperature type to Celsius. This is the default
-option.\n\n",
- );
+ .long_help("Sets the temperature type to Celsius. This is the default option.");
- // All flags. These are in alphabetical order
- let autohide_time = Arg::with_name("autohide_time")
+ // All flags. These are in alphabetical order
+ let autohide_time = Arg::new("autohide_time")
.long("autohide_time")
.help("Temporarily shows the time scale in graphs.")
.long_help(
- "\
-Automatically hides the time scale in graphs after being
-shown for a brief moment when zoomed in/out. If time is
-disabled via --hide_time then this will have no effect.\n\n\n",
+ "Automatically hides the time scale in graphs after being shown for \
+ a brief moment when zoomed in/out. If time is disabled via --hide_time \
+ then this will have no effect.",
);
- let basic = Arg::with_name("basic")
- .short("b")
+
+ let basic = Arg::new("basic")
+ .short('b')
.long("basic")
.help("Hides graphs and uses a more basic look.")
.long_help(
- "\
-Hides graphs and uses a more basic look. Design is largely
-inspired by htop's.\n\n",
+ "Hides graphs and uses a more basic look. Design is largely inspired by htop's.",
);
- let case_sensitive = Arg::with_name("case_sensitive")
- .short("S")
+
+ let case_sensitive = Arg::new("case_sensitive")
+ .short('S')
.long("case_sensitive")
.help("Enables case sensitivity by default.")
- .long_help(
- "\
-When searching for a process, enables case sensitivity by default.\n\n",
- );
- let current_usage = Arg::with_name("current_usage")
- .short("u")
+ .long_help("When searching for a process, enables case sensitivity by default.");
+
+ let current_usage = Arg::new("current_usage")
+ .short('u')
.long("current_usage")
.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.\n\n",
- );
+ .long_help("Sets process CPU% usage to be based on the current system CPU% usage rather than total CPU usage.");
+
// TODO: [DEBUG] Add a proper debugging solution.
- // let debug = Arg::with_name("debug")
- // .long("debug")
- // .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")
+
+ let disable_click = Arg::new("disable_click")
.long("disable_click")
.help("Disables mouse clicks.")
- .long_help(
- "\
-Disables mouse clicks from interacting with the program.\n\n",
- );
+ .long_help("Disables mouse clicks from interacting with the program.");
- let dot_marker = Arg::with_name("dot_marker")
- .short("m")
+ let dot_marker = Arg::new("dot_marker")
+ .short('m')
.long("dot_marker")
.help("Uses a dot marker for graphs.")
- .long_help(
- "\
-Uses a dot marker for graphs as opposed to the default braille
-marker.\n\n",
- );
+ .long_help("Uses a dot marker for graphs as opposed to the default braille marker.");
- let group = Arg::with_name("group") // FIXME: Rename this to something like "group_process", would be "breaking" though.
- .short("g")
+ let group = Arg::new("group") // FIXME: Rename this to something like "group_process", would be "breaking" though.
+ .short('g')
.long("group")
.help("Groups processes with the same name by default.")
- .long_help(
- "\
-Groups processes with the same name by default.\n\n",
- );
+ .long_help("Groups processes with the same name by default.");
- let hide_avg_cpu = Arg::with_name("hide_avg_cpu")
- .short("a")
+ let hide_avg_cpu = Arg::new("hide_avg_cpu")
+ .short('a')
.long("hide_avg_cpu")
.help("Hides the average CPU usage.")
- .long_help(
- "\
-Hides the average CPU usage from being shown.\n\n",
- );
+ .long_help("Hides the average CPU usage from being shown.");
- let hide_table_gap = Arg::with_name("hide_table_gap")
+ let hide_table_gap = Arg::new("hide_table_gap")
.long("hide_table_gap")
.help("Hides the spacing between table headers and entries.")
- .long_help(
- "\
-Hides the spacing between table headers and entries.\n\n",
- );
+ .long_help("Hides the spacing between table headers and entries.");
- let hide_time = Arg::with_name("hide_time")
+ let hide_time = Arg::new("hide_time")
.long("hide_time")
.help("Hides the time scale.")
- .long_help(
- "\
-Completely hides the time scale from being shown.\n\n",
- );
+ .long_help("Completely hides the time scale from being shown.");
- let process_command = Arg::with_name("process_command")
+ let process_command = Arg::new("process_command")
.long("process_command")
.help("Show processes as their commands by default.")
- .long_help(
- "\
- Show processes as their commands by default in the process widget.
- ",
- );
+ .long_help("Show processes as their commands by default in the process widget.");
- let left_legend = Arg::with_name("left_legend")
- .short("l")
+ let left_legend = Arg::new("left_legend")
+ .short('l')
.long("left_legend")
.help("Puts the CPU chart legend to the left side.")
- .long_help(
- "\
-Puts the CPU chart legend to the left side rather than the right side.\n\n",
- );
+ .long_help("Puts the CPU chart legend to the left side rather than the right side.");
- // let no_write = Arg::with_name("no_write")
- // .long("no_write")
- // .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")
+ let regex = Arg::new("regex")
+ .short('R')
.long("regex")
.help("Enables regex by default.")
- .long_help(
- "\
-When searching for a process, enables regex by default.\n\n",
- );
+ .long_help("When searching for a process, enables regex by default.");
- let disable_advanced_kill = Arg::with_name("disable_advanced_kill")
+ let disable_advanced_kill = Arg::new("disable_advanced_kill")
.long("disable_advanced_kill")
.help("Hides advanced options to stop a process on Unix-like systems.")
- .long_help(
- "\
-Hides advanced options to stop a process on Unix-like systems. The only option shown is -15.\n\n",
- );
+ .long_help("Hides advanced options to stop a process on Unix-like systems. The only option shown is -15.");
- 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")
.help("Shows the scroll position tracker in table widgets.")
- .long_help(
- "\
- Shows the list scroll position tracker in the widget title for table widgets.\n\n",
- );
+ .long_help("Shows the list scroll position tracker in the widget title for table widgets.");
- 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")
- .help("DEPRECATED - uses the older network legend.")
+ .help("DEPRECATED - uses a separate network legend.")
.long_help(
- "\
-DEPRECATED - uses the older (pre-0.4) network widget legend.
-This display is not tested anymore and could be broken.\n\n\n",
+ "DEPRECATED - uses an older (pre-0.4), separate network widget legend. This display is not \
+ tested anymore and could be broken.",
);
- let whole_word = Arg::with_name("whole_word")
- .short("W")
+ let whole_word = Arg::new("whole_word")
+ .short('W')
.long("whole_word")
.help("Enables whole-word matching by default.")
.long_help(
- "\
-When searching for a process, return results that match the
-entire query by default.\n\n",
+ "When searching for a process, return results that match the entire query by default.",
);
- // All options. Again, alphabetical order.
- let config_location = Arg::with_name("config_location")
- .short("C")
+ // All options. Again, alphabetical order.
+ let config_location = Arg::new("config_location")
+ .short('C')
.long("config")
.takes_value(true)
.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.\n\n\n",
+ "Sets the location of the config file. Expects a config file in the TOML format. \
+ If it doesn't exist, one is created.",
);
- let color = Arg::with_name("color")
+
+ let color = Arg::new("color")
.long("color")
.takes_value(true)
.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.")
.long_help(
"\
-Use a pre-defined color scheme. Currently supported values are:
+Use a pre-defined color scheme. Currently supported values are:
+------------------------------------------------------------+
| default |
@@ -316,37 +258,23 @@ Use a pre-defined color scheme. Currently supported values are:
+------------------------------------------------------------+
Defaults to \"default\".
-\n\n",
- )
- .possible_values(&[
- "default",
- "default-light",
- "gruvbox",
- "gruvbox-light",
- "nord",
- "nord-light",
- ])
- .hide_possible_values(true);
- let mem_as_value = Arg::with_name("mem_as_value")
+",
+ );
+
+ let mem_as_value = Arg::new("mem_as_value")
.long("mem_as_value")
.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.\n\n",
- );
- let default_time_value = Arg::with_name("default_time_value")
- .short("t")
+ .long_help("Defaults to showing process memory usage by value. Otherwise, it defaults to showing it by percentage.");
+
+ let default_time_value = Arg::new("default_time_value")
+ .short('t')
.long("default_time_value")
.takes_value(true)
.value_name("MS")
.help("Default time value for graphs in ms.")
- .long_help(
- "\
-Default time value for graphs in milliseconds. The minimum
-time is 30s (30000), and the default is 60s (60000).\n\n\n",
- );
- let default_widget_count = Arg::with_name("default_widget_count")
+ .long_help("Default time value for graphs in milliseconds. The minimum time is 30s (30000), and the default is 60s (60000).");
+
+ let default_widget_count = Arg::new("default_widget_count")
.long("default_widget_count")
.takes_value(true)
.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.
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:
+-------------------+-----------------------+
| CPU (1) | CPU (2) |
@@ -365,87 +293,73 @@ we have a layout that looks like:
| 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
-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.
-\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")
.takes_value(true)
.value_name("WIDGET TYPE")
.help("Sets the default widget type, use --help for more info.")
.long_help(DEFAULT_WIDGET_TYPE_STR);
- let rate = Arg::with_name("rate")
- .short("r")
+
+ let rate = Arg::new("rate")
+ .short('r')
.long("rate")
.takes_value(true)
.value_name("MS")
.help("Sets a refresh rate in ms.")
- .long_help(
- "\
-Sets a refresh rate in milliseconds. The minimum is 250ms,
-and defaults to 1000ms. Smaller values may take more resources.\n\n\n",
- );
- let time_delta = Arg::with_name("time_delta")
- .short("d")
+ .long_help("Sets a refresh rate in milliseconds. The minimum is 250ms, and defaults to 1000ms. Smaller values may take more computer resources.");
+
+ let time_delta = Arg::new("time_delta")
+ .short('d')
.long("time_delta")
.takes_value(true)
.value_name("MS")
.help("The amount in ms changed upon zooming.")
- .long_help(
- "\
-The amount of time in milliseconds changed when zooming in/out.
-The minimum is 1s (1000), and defaults to 15s (15000).\n\n\n",
- );
+ .long_help("The amount of time in milliseconds changed when zooming in/out. The minimum is 1s (1000), and defaults to 15s (15000).");
- let tree = Arg::with_name("tree")
- .short("T")
+ let tree = Arg::new("tree")
+ .short('T')
.long("tree")
.help("Defaults to showing the process widget in tree mode.")
- .long_help(
- "\
-Defaults to showing the process widget in tree mode.\n\n",
- );
+ .long_help("Defaults to showing the process widget in tree mode.");
- let network_use_bytes = Arg::with_name("network_use_bytes")
+ let network_use_bytes = Arg::new("network_use_bytes")
.long("network_use_bytes")
.help("Displays the network widget using bytes.")
- .long_help(
- "\
-Displays the network widget using bytes. Defaults to bits.\n\n",
- );
+ .long_help("Displays the network widget using bytes. Defaults to bits.");
- let network_use_log = Arg::with_name("network_use_log")
+ let network_use_log = Arg::new("network_use_log")
.long("network_use_log")
.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.\n\n",
- );
+ .long_help("Displays the network widget with a log scale. Defaults to a non-log scale.");
- 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")
.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.\n\n\n",
+ "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 app = App::new(crate_name!())
- .setting(AppSettings::UnifiedHelpMessage)
+ let app = Command::new(crate_name!())
.version(crate_version!())
.author(crate_authors!())
.about(crate_description!())
- .template(TEMPLATE)
- .usage(USAGE)
- .help_message("Prints help information. Use --help for more info.")
- .version_message("Prints version information.")
+ .override_usage(USAGE)
+ .help_template(TEMPLATE)
+ .mut_arg("help", |a| {
+ a.help("Prints help information. Use --help for more info.")
+ })
+ .mut_arg("version", |a| a.help("Prints version information."))
.arg(kelvin)
.arg(fahrenheit)
.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(basic)
.arg(case_sensitive)
@@ -477,13 +391,11 @@ Displays the network widget with binary prefixes (i.e. kibibits, mebibits) rathe
.arg(whole_word);
let app = if cfg!(feature = "battery") {
- let battery = Arg::with_name("battery")
+ let battery = Arg::new("battery")
.long("battery")
.help("Shows the battery widget.")
.long_help(
- "\
-Shows the battery widget in default or basic mode. No effect on
-custom layouts.\n\n",
+ "Shows the battery widget in default or basic mode. No effect on custom layouts.",
);
app.arg(battery)
} else {
diff --git a/src/options.rs b/src/options.rs
index bdbc7e60..d469dc69 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -244,7 +244,7 @@ pub struct IgnoreList {
}
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>,
config_path: Option<PathBuf>,
) -> Result<App> {
@@ -524,7 +524,7 @@ pub fn build_app(
}
pub fn get_widget_layout(
- matches: &clap::ArgMatches<'static>, config: &Config,
+ matches: &clap::ArgMatches, config: &Config,
) -> error::Result<(BottomLayout, u64, Option<BottomWidgetType>)> {
let left_legend = get_use_left_legend(matches, config);
let (default_widget_type, mut default_widget_count) =
@@ -589,7 +589,7 @@ pub fn get_widget_layout(
}
fn get_update_rate_in_milliseconds(
- matches: &clap::ArgMatches<'static>, config: &Config,
+ matches: &clap::ArgMatches, config: &Config,
) -> error::Result<u64> {
let update_rate_in_milliseconds = if let Some(update_rate) = matches.value_of("rate") {
update_rate.parse::<u128>()?
@@ -617,7 +617,7 @@ fn get_update_rate_in_milliseconds(
}
fn get_temperature(
- matches: &clap::ArgMatches<'static>, config: &Config,
+ matches: &clap::ArgMatches, config: &Config,
) -> error::Result<data_harvester::temperature::TemperatureType> {
if matches.is_present("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)
-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") {
return false;
} else if let Some(flags) = &config.flags {
@@ -655,7 +655,7 @@ fn get_show_average_cpu(matches: &clap::ArgMatches<'static>, config: &Config) ->
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") {
return true;
} else if let Some(flags) = &config.flags {
@@ -666,7 +666,7 @@ fn get_use_dot(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
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") {
return true;
} else if let Some(flags) = &config.flags {
@@ -678,7 +678,7 @@ fn get_use_left_legend(matches: &clap::ArgMatches<'static>, config: &Config) ->
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") {
return true;
} else if let Some(flags) = &config.flags {
@@ -690,7 +690,7 @@ fn get_use_current_cpu_total(matches: &clap::ArgMatches<'static>, config: &Confi
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") {
return true;
} else if let Some(flags) = &config.flags {
@@ -702,9 +702,7 @@ fn get_use_basic_mode(matches: &clap::ArgMatches<'static>, config: &Config) -> b
false
}
-fn get_default_time_value(
- matches: &clap::ArgMatches<'static>, config: &Config,
-) -> error::Result<u64> {
+fn get_default_time_value(matches: &clap::ArgMatches, config: &Config) -> error::Result<u64> {
let default_time = if let Some(default_time_value) = matches.value_of("default_time_value") {
default_time_value.parse::<u128>()?
} else if let Some(flags) = &config.flags {
@@ -731,7 +729,7 @@ fn get_default_time_value(
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") {
time_interval.parse::<u128>()?
} 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)
}
-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") {
return true;
} else if let Some(flags) = &config.flags {
@@ -769,7 +767,7 @@ pub fn get_app_grouping(matches: &clap::ArgMatches<'static>, config: &Config) ->
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") {
return true;
} else if let Some(flags) = &config.flags {
@@ -780,7 +778,7 @@ pub fn get_app_case_sensitive(matches: &clap::ArgMatches<'static>, config: &Conf
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") {
return true;
} 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
}
-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") {
return true;
} else if let Some(flags) = &config.flags {
@@ -802,7 +800,7 @@ pub fn get_app_use_regex(matches: &clap::ArgMatches<'static>, config: &Config) -
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") {
return true;
} else if let Some(flags) = &config.flags {
@@ -813,7 +811,7 @@ fn get_hide_time(matches: &clap::ArgMatches<'static>, config: &Config) -> bool {
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") {
return true;
} 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(
- matches: &clap::ArgMatches<'static>, config: &Config,
+ matches: &clap::ArgMatches, config: &Config,
) -> error::Result<(Option<BottomWidgetType>, u64)> {
let widget_type = if let Some(widget_type) = matches.value_of("default_widget_type") {
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_