mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-22 13:14:40 +02:00
other: replace deprecated value_of
and is_present
in clap
* Upgrade clap to 3.2.2 to allow future fix warnings * cargo fmt fix * Replaced deprecated `value_of` and `is_present`, builds with no warnings, clap 3.2.2 * cargo fmt * updated according to comments. builds fine, cargo test fine * Match some versions * Update Cargo.lock * Fix typo, mb --------- Co-authored-by: Clement Tsang <34804052+ClementTsang@users.noreply.github.com>
This commit is contained in:
parent
9ad1d8f0b4
commit
021a727f19
16
Cargo.lock
generated
16
Cargo.lock
generated
@ -304,9 +304,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap"
|
name = "clap"
|
||||||
version = "3.1.12"
|
version = "3.2.2"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "7c167e37342afc5f33fd87bbc870cedd020d2a6dffa05d45ccd9241fbdd146db"
|
checksum = "8e538f9ee5aa3b3963f09a997035f883677966ed50fce0292611927ce6f6d8c6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"atty",
|
"atty",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
@ -321,27 +321,27 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_complete"
|
name = "clap_complete"
|
||||||
version = "3.1.2"
|
version = "3.2.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "1506b87ee866f7a53a5131f7b31fba656170d797e873d0609884cfd56b8bbda8"
|
checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_lex"
|
name = "clap_lex"
|
||||||
version = "0.1.1"
|
version = "0.2.4"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "189ddd3b5d32a70b35e7686054371742a937b0d99128e76dde6340210e966669"
|
checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"os_str_bytes",
|
"os_str_bytes",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_mangen"
|
name = "clap_mangen"
|
||||||
version = "0.1.6"
|
version = "0.1.11"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ca2ff85c3fa1e7c1a4229f7b4221f769757c3982e2afd3e6d9381d59db2c7e61"
|
checksum = "105180c05a72388d5f5e4e4f6c79eecb92497bda749fa8f963a16647c5d5377f"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"clap",
|
"clap",
|
||||||
"roff",
|
"roff",
|
||||||
|
@ -65,7 +65,7 @@ deploy = ["battery", "gpu", "zfs"]
|
|||||||
anyhow = "1.0.57"
|
anyhow = "1.0.57"
|
||||||
backtrace = "0.3.67"
|
backtrace = "0.3.67"
|
||||||
cfg-if = "1.0.0"
|
cfg-if = "1.0.0"
|
||||||
clap = { version = "3.1.12", features = ["default", "cargo", "wrap_help"] }
|
clap = { version = "3.2.2", features = ["default", "cargo", "wrap_help"] }
|
||||||
concat-string = "1.0.1"
|
concat-string = "1.0.1"
|
||||||
const_format = "0.2.30"
|
const_format = "0.2.30"
|
||||||
crossterm = "0.25.0"
|
crossterm = "0.25.0"
|
||||||
@ -115,6 +115,7 @@ features = ["user-hooks"]
|
|||||||
[target.'cfg(target_os = "windows")'.dependencies]
|
[target.'cfg(target_os = "windows")'.dependencies]
|
||||||
heim = { version = "0.1.0-rc.1", features = ["cpu", "disk", "memory"] }
|
heim = { version = "0.1.0-rc.1", features = ["cpu", "disk", "memory"] }
|
||||||
windows = { version = "0.44.0", features = ["Win32_System_Threading", "Win32_Foundation"] }
|
windows = { version = "0.44.0", features = ["Win32_System_Threading", "Win32_Foundation"] }
|
||||||
|
|
||||||
winapi = "0.3.9"
|
winapi = "0.3.9"
|
||||||
|
|
||||||
[target.'cfg(target_os = "freebsd")'.dependencies]
|
[target.'cfg(target_os = "freebsd")'.dependencies]
|
||||||
@ -127,9 +128,9 @@ assert_cmd = "2.0.4"
|
|||||||
predicates = "2.1.1"
|
predicates = "2.1.1"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
clap = { version = "3.1.12", features = ["default", "cargo", "wrap_help"] }
|
clap = { version = "3.2.2", features = ["default", "cargo", "wrap_help"] }
|
||||||
clap_complete = "3.1.2"
|
clap_complete = "3.2.4"
|
||||||
clap_mangen = "0.1.6"
|
clap_mangen = "0.1.11"
|
||||||
|
|
||||||
[package.metadata.deb]
|
[package.metadata.deb]
|
||||||
section = "utility"
|
section = "utility"
|
||||||
|
@ -43,7 +43,7 @@ fn main() -> Result<()> {
|
|||||||
check_if_terminal();
|
check_if_terminal();
|
||||||
|
|
||||||
// Read from config file.
|
// Read from config file.
|
||||||
let config_path = read_config(matches.value_of("config_location"))
|
let config_path = read_config(matches.get_one::<String>("config_location"))
|
||||||
.context("Unable to access the given config file location.")?;
|
.context("Unable to access the given config file location.")?;
|
||||||
let mut config: Config = create_or_get_config(&config_path)
|
let mut config: Config = create_or_get_config(&config_path)
|
||||||
.context("Unable to properly parse or create the config file.")?;
|
.context("Unable to properly parse or create the config file.")?;
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
use clap::builder::PossibleValuesParser;
|
||||||
use clap::*;
|
use clap::*;
|
||||||
|
|
||||||
const TEMPLATE: &str = "\
|
const TEMPLATE: &str = "\
|
||||||
@ -237,14 +238,14 @@ pub fn build_app() -> Command<'static> {
|
|||||||
.long("color")
|
.long("color")
|
||||||
.takes_value(true)
|
.takes_value(true)
|
||||||
.value_name("COLOR SCHEME")
|
.value_name("COLOR SCHEME")
|
||||||
.possible_values([
|
.value_parser(PossibleValuesParser::new([
|
||||||
"default",
|
"default",
|
||||||
"default-light",
|
"default-light",
|
||||||
"gruvbox",
|
"gruvbox",
|
||||||
"gruvbox-light",
|
"gruvbox-light",
|
||||||
"nord",
|
"nord",
|
||||||
"nord-light",
|
"nord-light",
|
||||||
])
|
]))
|
||||||
.hide_possible_values(true)
|
.hide_possible_values(true)
|
||||||
.help("Use a color scheme, use --help for info.")
|
.help("Use a color scheme, use --help for info.")
|
||||||
.long_help(
|
.long_help(
|
||||||
|
@ -200,9 +200,9 @@ pub fn handle_key_event_or_break(
|
|||||||
false
|
false
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read_config(config_location: Option<&str>) -> error::Result<Option<PathBuf>> {
|
pub fn read_config(config_location: Option<&String>) -> error::Result<Option<PathBuf>> {
|
||||||
let config_path = if let Some(conf_loc) = config_location {
|
let config_path = if let Some(conf_loc) = config_location {
|
||||||
Some(PathBuf::from(conf_loc))
|
Some(PathBuf::from(conf_loc.as_str()))
|
||||||
} else if cfg!(target_os = "windows") {
|
} else if cfg!(target_os = "windows") {
|
||||||
if let Some(home_path) = dirs::config_dir() {
|
if let Some(home_path) = dirs::config_dir() {
|
||||||
let mut path = home_path;
|
let mut path = home_path;
|
||||||
|
100
src/options.rs
100
src/options.rs
@ -498,7 +498,7 @@ pub fn get_widget_layout(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_update_rate_in_milliseconds(matches: &ArgMatches, config: &Config) -> error::Result<u64> {
|
fn get_update_rate_in_milliseconds(matches: &ArgMatches, config: &Config) -> 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.get_one::<String>("rate") {
|
||||||
update_rate.parse::<u64>().map_err(|_| {
|
update_rate.parse::<u64>().map_err(|_| {
|
||||||
BottomError::ConfigError(
|
BottomError::ConfigError(
|
||||||
"could not parse as a valid 64-bit unsigned integer".to_string(),
|
"could not parse as a valid 64-bit unsigned integer".to_string(),
|
||||||
@ -526,11 +526,11 @@ fn get_update_rate_in_milliseconds(matches: &ArgMatches, config: &Config) -> err
|
|||||||
fn get_temperature(
|
fn get_temperature(
|
||||||
matches: &ArgMatches, config: &Config,
|
matches: &ArgMatches, config: &Config,
|
||||||
) -> error::Result<data_harvester::temperature::TemperatureType> {
|
) -> error::Result<data_harvester::temperature::TemperatureType> {
|
||||||
if matches.is_present("fahrenheit") {
|
if matches.contains_id("fahrenheit") {
|
||||||
return Ok(data_harvester::temperature::TemperatureType::Fahrenheit);
|
return Ok(data_harvester::temperature::TemperatureType::Fahrenheit);
|
||||||
} else if matches.is_present("kelvin") {
|
} else if matches.contains_id("kelvin") {
|
||||||
return Ok(data_harvester::temperature::TemperatureType::Kelvin);
|
return Ok(data_harvester::temperature::TemperatureType::Kelvin);
|
||||||
} else if matches.is_present("celsius") {
|
} else if matches.contains_id("celsius") {
|
||||||
return Ok(data_harvester::temperature::TemperatureType::Celsius);
|
return Ok(data_harvester::temperature::TemperatureType::Celsius);
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(temp_type) = &flags.temperature_type {
|
if let Some(temp_type) = &flags.temperature_type {
|
||||||
@ -551,7 +551,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: &ArgMatches, config: &Config) -> bool {
|
fn get_show_average_cpu(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("hide_avg_cpu") {
|
if matches.contains_id("hide_avg_cpu") {
|
||||||
return false;
|
return false;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(avg_cpu) = flags.hide_avg_cpu {
|
if let Some(avg_cpu) = flags.hide_avg_cpu {
|
||||||
@ -563,7 +563,7 @@ fn get_show_average_cpu(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_use_dot(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_use_dot(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("dot_marker") {
|
if matches.contains_id("dot_marker") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(dot_marker) = flags.dot_marker {
|
if let Some(dot_marker) = flags.dot_marker {
|
||||||
@ -574,7 +574,7 @@ fn get_use_dot(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_use_left_legend(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_use_left_legend(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("left_legend") {
|
if matches.contains_id("left_legend") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(left_legend) = flags.left_legend {
|
if let Some(left_legend) = flags.left_legend {
|
||||||
@ -586,7 +586,7 @@ fn get_use_left_legend(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_use_current_cpu_total(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_use_current_cpu_total(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("current_usage") {
|
if matches.contains_id("current_usage") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(current_usage) = flags.current_usage {
|
if let Some(current_usage) = flags.current_usage {
|
||||||
@ -598,7 +598,7 @@ fn get_use_current_cpu_total(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_unnormalized_cpu(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_unnormalized_cpu(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("unnormalized_cpu") {
|
if matches.contains_id("unnormalized_cpu") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(unnormalized_cpu) = flags.unnormalized_cpu {
|
if let Some(unnormalized_cpu) = flags.unnormalized_cpu {
|
||||||
@ -610,7 +610,7 @@ fn get_unnormalized_cpu(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_use_basic_mode(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_use_basic_mode(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("basic") {
|
if matches.contains_id("basic") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(basic) = flags.basic {
|
if let Some(basic) = flags.basic {
|
||||||
@ -625,21 +625,22 @@ fn get_use_basic_mode(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
fn get_default_time_value(
|
fn get_default_time_value(
|
||||||
matches: &ArgMatches, config: &Config, retention_ms: u64,
|
matches: &ArgMatches, config: &Config, retention_ms: u64,
|
||||||
) -> error::Result<u64> {
|
) -> error::Result<u64> {
|
||||||
let default_time = if let Some(default_time_value) = matches.value_of("default_time_value") {
|
let default_time =
|
||||||
default_time_value.parse::<u64>().map_err(|_| {
|
if let Some(default_time_value) = matches.get_one::<String>("default_time_value") {
|
||||||
BottomError::ConfigError(
|
default_time_value.parse::<u64>().map_err(|_| {
|
||||||
"could not parse as a valid 64-bit unsigned integer".to_string(),
|
BottomError::ConfigError(
|
||||||
)
|
"could not parse as a valid 64-bit unsigned integer".to_string(),
|
||||||
})?
|
)
|
||||||
} else if let Some(flags) = &config.flags {
|
})?
|
||||||
if let Some(default_time_value) = flags.default_time_value {
|
} else if let Some(flags) = &config.flags {
|
||||||
default_time_value
|
if let Some(default_time_value) = flags.default_time_value {
|
||||||
|
default_time_value
|
||||||
|
} else {
|
||||||
|
DEFAULT_TIME_MILLISECONDS
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
DEFAULT_TIME_MILLISECONDS
|
DEFAULT_TIME_MILLISECONDS
|
||||||
}
|
};
|
||||||
} else {
|
|
||||||
DEFAULT_TIME_MILLISECONDS
|
|
||||||
};
|
|
||||||
|
|
||||||
if default_time < 30000 {
|
if default_time < 30000 {
|
||||||
return Err(BottomError::ConfigError(
|
return Err(BottomError::ConfigError(
|
||||||
@ -658,7 +659,7 @@ fn get_default_time_value(
|
|||||||
fn get_time_interval(
|
fn get_time_interval(
|
||||||
matches: &ArgMatches, config: &Config, retention_ms: u64,
|
matches: &ArgMatches, config: &Config, retention_ms: u64,
|
||||||
) -> error::Result<u64> {
|
) -> 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.get_one::<String>("time_delta") {
|
||||||
time_interval.parse::<u64>().map_err(|_| {
|
time_interval.parse::<u64>().map_err(|_| {
|
||||||
BottomError::ConfigError(
|
BottomError::ConfigError(
|
||||||
"could not parse as a valid 64-bit unsigned integer".to_string(),
|
"could not parse as a valid 64-bit unsigned integer".to_string(),
|
||||||
@ -689,7 +690,7 @@ fn get_time_interval(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_app_grouping(matches: &ArgMatches, config: &Config) -> bool {
|
pub fn get_app_grouping(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("group") {
|
if matches.contains_id("group") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(grouping) = flags.group_processes {
|
if let Some(grouping) = flags.group_processes {
|
||||||
@ -700,7 +701,7 @@ pub fn get_app_grouping(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_app_case_sensitive(matches: &ArgMatches, config: &Config) -> bool {
|
pub fn get_app_case_sensitive(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("case_sensitive") {
|
if matches.contains_id("case_sensitive") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(case_sensitive) = flags.case_sensitive {
|
if let Some(case_sensitive) = flags.case_sensitive {
|
||||||
@ -711,7 +712,7 @@ pub fn get_app_case_sensitive(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_app_match_whole_word(matches: &ArgMatches, config: &Config) -> bool {
|
pub fn get_app_match_whole_word(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("whole_word") {
|
if matches.contains_id("whole_word") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(whole_word) = flags.whole_word {
|
if let Some(whole_word) = flags.whole_word {
|
||||||
@ -722,7 +723,7 @@ pub fn get_app_match_whole_word(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_app_use_regex(matches: &ArgMatches, config: &Config) -> bool {
|
pub fn get_app_use_regex(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("regex") {
|
if matches.contains_id("regex") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(regex) = flags.regex {
|
if let Some(regex) = flags.regex {
|
||||||
@ -733,7 +734,7 @@ pub fn get_app_use_regex(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_hide_time(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_hide_time(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("hide_time") {
|
if matches.contains_id("hide_time") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(hide_time) = flags.hide_time {
|
if let Some(hide_time) = flags.hide_time {
|
||||||
@ -744,7 +745,7 @@ fn get_hide_time(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_autohide_time(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_autohide_time(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("autohide_time") {
|
if matches.contains_id("autohide_time") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(autohide_time) = flags.autohide_time {
|
if let Some(autohide_time) = flags.autohide_time {
|
||||||
@ -756,7 +757,7 @@ fn get_autohide_time(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_expanded_on_startup(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_expanded_on_startup(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
matches.is_present("expanded_on_startup")
|
matches.contains_id("expanded_on_startup")
|
||||||
|| config
|
|| config
|
||||||
.flags
|
.flags
|
||||||
.as_ref()
|
.as_ref()
|
||||||
@ -767,7 +768,7 @@ fn get_expanded_on_startup(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
fn get_default_widget_and_count(
|
fn get_default_widget_and_count(
|
||||||
matches: &ArgMatches, config: &Config,
|
matches: &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.get_one::<String>("default_widget_type") {
|
||||||
let parsed_widget = widget_type.parse::<BottomWidgetType>()?;
|
let parsed_widget = widget_type.parse::<BottomWidgetType>()?;
|
||||||
if let BottomWidgetType::Empty = parsed_widget {
|
if let BottomWidgetType::Empty = parsed_widget {
|
||||||
None
|
None
|
||||||
@ -789,7 +790,8 @@ fn get_default_widget_and_count(
|
|||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|
||||||
let widget_count = if let Some(widget_count) = matches.value_of("default_widget_count") {
|
let widget_count = if let Some(widget_count) = matches.get_one::<String>("default_widget_count")
|
||||||
|
{
|
||||||
Some(widget_count.parse::<u128>()?)
|
Some(widget_count.parse::<u128>()?)
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
flags
|
flags
|
||||||
@ -815,7 +817,7 @@ fn get_default_widget_and_count(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_disable_click(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_disable_click(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("disable_click") {
|
if matches.contains_id("disable_click") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(disable_click) = flags.disable_click {
|
if let Some(disable_click) = flags.disable_click {
|
||||||
@ -826,7 +828,7 @@ fn get_disable_click(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_use_old_network_legend(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_use_old_network_legend(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("use_old_network_legend") {
|
if matches.contains_id("use_old_network_legend") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(use_old_network_legend) = flags.use_old_network_legend {
|
if let Some(use_old_network_legend) = flags.use_old_network_legend {
|
||||||
@ -837,7 +839,7 @@ fn get_use_old_network_legend(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_hide_table_gap(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_hide_table_gap(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("hide_table_gap") {
|
if matches.contains_id("hide_table_gap") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(hide_table_gap) = flags.hide_table_gap {
|
if let Some(hide_table_gap) = flags.hide_table_gap {
|
||||||
@ -858,7 +860,7 @@ fn get_use_battery(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(feature = "battery") {
|
if cfg!(feature = "battery") {
|
||||||
if matches.is_present("battery") {
|
if matches.contains_id("battery") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(battery) = flags.battery {
|
if let Some(battery) = flags.battery {
|
||||||
@ -871,7 +873,7 @@ fn get_use_battery(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
|
|
||||||
fn get_enable_gpu_memory(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_enable_gpu_memory(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if cfg!(feature = "gpu") {
|
if cfg!(feature = "gpu") {
|
||||||
if matches.is_present("enable_gpu_memory") {
|
if matches.contains_id("enable_gpu_memory") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(enable_gpu_memory) = flags.enable_gpu_memory {
|
if let Some(enable_gpu_memory) = flags.enable_gpu_memory {
|
||||||
@ -884,7 +886,7 @@ fn get_enable_gpu_memory(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
fn get_no_write(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_no_write(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("no_write") {
|
if matches.contains_id("no_write") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(no_write) = flags.no_write {
|
if let Some(no_write) = flags.no_write {
|
||||||
@ -932,7 +934,7 @@ fn get_ignore_list(ignore_list: &Option<IgnoreList>) -> error::Result<Option<Fil
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_color_scheme(matches: &ArgMatches, config: &Config) -> error::Result<ColourScheme> {
|
pub fn get_color_scheme(matches: &ArgMatches, config: &Config) -> error::Result<ColourScheme> {
|
||||||
if let Some(color) = matches.value_of("color") {
|
if let Some(color) = matches.get_one::<String>("color") {
|
||||||
// Highest priority is always command line flags...
|
// Highest priority is always command line flags...
|
||||||
return ColourScheme::from_str(color);
|
return ColourScheme::from_str(color);
|
||||||
} else if let Some(colors) = &config.colors {
|
} else if let Some(colors) = &config.colors {
|
||||||
@ -957,7 +959,7 @@ pub fn get_color_scheme(matches: &ArgMatches, config: &Config) -> error::Result<
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_mem_as_value(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_mem_as_value(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("mem_as_value") {
|
if matches.contains_id("mem_as_value") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(mem_as_value) = flags.mem_as_value {
|
if let Some(mem_as_value) = flags.mem_as_value {
|
||||||
@ -968,7 +970,7 @@ fn get_mem_as_value(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_is_default_tree(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_is_default_tree(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("tree") {
|
if matches.contains_id("tree") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(tree) = flags.tree {
|
if let Some(tree) = flags.tree {
|
||||||
@ -979,7 +981,7 @@ fn get_is_default_tree(matches: &ArgMatches, config: &Config) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_show_table_scroll_position(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_show_table_scroll_position(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("show_table_scroll_position") {
|
if matches.contains_id("show_table_scroll_position") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(show_table_scroll_position) = flags.show_table_scroll_position {
|
if let Some(show_table_scroll_position) = flags.show_table_scroll_position {
|
||||||
@ -990,7 +992,7 @@ fn get_show_table_scroll_position(matches: &ArgMatches, config: &Config) -> bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_is_default_process_command(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_is_default_process_command(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("process_command") {
|
if matches.contains_id("process_command") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(process_command) = flags.process_command {
|
if let Some(process_command) = flags.process_command {
|
||||||
@ -1001,7 +1003,7 @@ fn get_is_default_process_command(matches: &ArgMatches, config: &Config) -> bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_is_advanced_kill_disabled(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_is_advanced_kill_disabled(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("disable_advanced_kill") {
|
if matches.contains_id("disable_advanced_kill") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(disable_advanced_kill) = flags.disable_advanced_kill {
|
if let Some(disable_advanced_kill) = flags.disable_advanced_kill {
|
||||||
@ -1012,7 +1014,7 @@ fn get_is_advanced_kill_disabled(matches: &ArgMatches, config: &Config) -> bool
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_network_unit_type(matches: &ArgMatches, config: &Config) -> DataUnit {
|
fn get_network_unit_type(matches: &ArgMatches, config: &Config) -> DataUnit {
|
||||||
if matches.is_present("network_use_bytes") {
|
if matches.contains_id("network_use_bytes") {
|
||||||
return DataUnit::Byte;
|
return DataUnit::Byte;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(network_use_bytes) = flags.network_use_bytes {
|
if let Some(network_use_bytes) = flags.network_use_bytes {
|
||||||
@ -1026,7 +1028,7 @@ fn get_network_unit_type(matches: &ArgMatches, config: &Config) -> DataUnit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_network_scale_type(matches: &ArgMatches, config: &Config) -> AxisScaling {
|
fn get_network_scale_type(matches: &ArgMatches, config: &Config) -> AxisScaling {
|
||||||
if matches.is_present("network_use_log") {
|
if matches.contains_id("network_use_log") {
|
||||||
return AxisScaling::Log;
|
return AxisScaling::Log;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(network_use_log) = flags.network_use_log {
|
if let Some(network_use_log) = flags.network_use_log {
|
||||||
@ -1040,7 +1042,7 @@ fn get_network_scale_type(matches: &ArgMatches, config: &Config) -> AxisScaling
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn get_network_use_binary_prefix(matches: &ArgMatches, config: &Config) -> bool {
|
fn get_network_use_binary_prefix(matches: &ArgMatches, config: &Config) -> bool {
|
||||||
if matches.is_present("network_use_binary_prefix") {
|
if matches.contains_id("network_use_binary_prefix") {
|
||||||
return true;
|
return true;
|
||||||
} else if let Some(flags) = &config.flags {
|
} else if let Some(flags) = &config.flags {
|
||||||
if let Some(network_use_binary_prefix) = flags.network_use_binary_prefix {
|
if let Some(network_use_binary_prefix) = flags.network_use_binary_prefix {
|
||||||
@ -1053,7 +1055,7 @@ fn get_network_use_binary_prefix(matches: &ArgMatches, config: &Config) -> bool
|
|||||||
fn get_retention_ms(matches: &ArgMatches, config: &Config) -> error::Result<u64> {
|
fn get_retention_ms(matches: &ArgMatches, config: &Config) -> error::Result<u64> {
|
||||||
const DEFAULT_RETENTION_MS: u64 = 600 * 1000; // Keep 10 minutes of data.
|
const DEFAULT_RETENTION_MS: u64 = 600 * 1000; // Keep 10 minutes of data.
|
||||||
|
|
||||||
if let Some(retention) = matches.value_of("retention") {
|
if let Some(retention) = matches.get_one::<String>("retention") {
|
||||||
humantime::parse_duration(retention)
|
humantime::parse_duration(retention)
|
||||||
.map(|dur| dur.as_millis() as u64)
|
.map(|dur| dur.as_millis() as u64)
|
||||||
.map_err(|err| BottomError::ConfigError(format!("invalid retention duration: {err:?}")))
|
.map_err(|err| BottomError::ConfigError(format!("invalid retention duration: {err:?}")))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user