diff --git a/Cargo.lock b/Cargo.lock index 170cebb3..949deed9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -304,9 +304,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "3.1.12" +version = "3.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7c167e37342afc5f33fd87bbc870cedd020d2a6dffa05d45ccd9241fbdd146db" +checksum = "8e538f9ee5aa3b3963f09a997035f883677966ed50fce0292611927ce6f6d8c6" dependencies = [ "atty", "bitflags", @@ -321,27 +321,27 @@ dependencies = [ [[package]] name = "clap_complete" -version = "3.1.2" +version = "3.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1506b87ee866f7a53a5131f7b31fba656170d797e873d0609884cfd56b8bbda8" +checksum = "3f7a2e0a962c45ce25afce14220bc24f9dade0a1787f185cecf96bfba7847cd8" dependencies = [ "clap", ] [[package]] name = "clap_lex" -version = "0.1.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "189ddd3b5d32a70b35e7686054371742a937b0d99128e76dde6340210e966669" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" dependencies = [ "os_str_bytes", ] [[package]] name = "clap_mangen" -version = "0.1.6" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2ff85c3fa1e7c1a4229f7b4221f769757c3982e2afd3e6d9381d59db2c7e61" +checksum = "105180c05a72388d5f5e4e4f6c79eecb92497bda749fa8f963a16647c5d5377f" dependencies = [ "clap", "roff", diff --git a/Cargo.toml b/Cargo.toml index 30c6c524..8bc91018 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -65,7 +65,7 @@ deploy = ["battery", "gpu", "zfs"] anyhow = "1.0.57" backtrace = "0.3.67" 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" const_format = "0.2.30" crossterm = "0.25.0" @@ -115,6 +115,7 @@ features = ["user-hooks"] [target.'cfg(target_os = "windows")'.dependencies] heim = { version = "0.1.0-rc.1", features = ["cpu", "disk", "memory"] } windows = { version = "0.44.0", features = ["Win32_System_Threading", "Win32_Foundation"] } + winapi = "0.3.9" [target.'cfg(target_os = "freebsd")'.dependencies] @@ -127,9 +128,9 @@ assert_cmd = "2.0.4" predicates = "2.1.1" [build-dependencies] -clap = { version = "3.1.12", features = ["default", "cargo", "wrap_help"] } -clap_complete = "3.1.2" -clap_mangen = "0.1.6" +clap = { version = "3.2.2", features = ["default", "cargo", "wrap_help"] } +clap_complete = "3.2.4" +clap_mangen = "0.1.11" [package.metadata.deb] section = "utility" diff --git a/src/bin/main.rs b/src/bin/main.rs index fe0b39fa..328cd7a0 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -43,7 +43,7 @@ fn main() -> Result<()> { check_if_terminal(); // Read from config file. - let config_path = read_config(matches.value_of("config_location")) + let config_path = read_config(matches.get_one::("config_location")) .context("Unable to access the given config file location.")?; let mut config: Config = create_or_get_config(&config_path) .context("Unable to properly parse or create the config file.")?; diff --git a/src/clap.rs b/src/clap.rs index f3333d8c..c7fa155b 100644 --- a/src/clap.rs +++ b/src/clap.rs @@ -1,3 +1,4 @@ +use clap::builder::PossibleValuesParser; use clap::*; const TEMPLATE: &str = "\ @@ -237,14 +238,14 @@ pub fn build_app() -> Command<'static> { .long("color") .takes_value(true) .value_name("COLOR SCHEME") - .possible_values([ + .value_parser(PossibleValuesParser::new([ "default", "default-light", "gruvbox", "gruvbox-light", "nord", "nord-light", - ]) + ])) .hide_possible_values(true) .help("Use a color scheme, use --help for info.") .long_help( diff --git a/src/lib.rs b/src/lib.rs index 33efbf42..ebc8baf5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -200,9 +200,9 @@ pub fn handle_key_event_or_break( false } -pub fn read_config(config_location: Option<&str>) -> error::Result> { +pub fn read_config(config_location: Option<&String>) -> error::Result> { 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") { if let Some(home_path) = dirs::config_dir() { let mut path = home_path; diff --git a/src/options.rs b/src/options.rs index 08690537..28c49a61 100644 --- a/src/options.rs +++ b/src/options.rs @@ -498,7 +498,7 @@ pub fn get_widget_layout( } fn get_update_rate_in_milliseconds(matches: &ArgMatches, config: &Config) -> error::Result { - 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::("rate") { update_rate.parse::().map_err(|_| { BottomError::ConfigError( "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( matches: &ArgMatches, config: &Config, ) -> error::Result { - if matches.is_present("fahrenheit") { + if matches.contains_id("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); - } else if matches.is_present("celsius") { + } else if matches.contains_id("celsius") { return Ok(data_harvester::temperature::TemperatureType::Celsius); } else if let Some(flags) = &config.flags { 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) 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; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("dot_marker") { + if matches.contains_id("dot_marker") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("left_legend") { + if matches.contains_id("left_legend") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("current_usage") { + if matches.contains_id("current_usage") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("unnormalized_cpu") { + if matches.contains_id("unnormalized_cpu") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("basic") { + if matches.contains_id("basic") { return true; } else if let Some(flags) = &config.flags { 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( matches: &ArgMatches, config: &Config, retention_ms: u64, ) -> error::Result { - let default_time = if let Some(default_time_value) = matches.value_of("default_time_value") { - default_time_value.parse::().map_err(|_| { - 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 { - default_time_value + let default_time = + if let Some(default_time_value) = matches.get_one::("default_time_value") { + default_time_value.parse::().map_err(|_| { + 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 { + default_time_value + } else { + DEFAULT_TIME_MILLISECONDS + } } else { DEFAULT_TIME_MILLISECONDS - } - } else { - DEFAULT_TIME_MILLISECONDS - }; + }; if default_time < 30000 { return Err(BottomError::ConfigError( @@ -658,7 +659,7 @@ fn get_default_time_value( fn get_time_interval( matches: &ArgMatches, config: &Config, retention_ms: u64, ) -> error::Result { - let time_interval = if let Some(time_interval) = matches.value_of("time_delta") { + let time_interval = if let Some(time_interval) = matches.get_one::("time_delta") { time_interval.parse::().map_err(|_| { BottomError::ConfigError( "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 { - if matches.is_present("group") { + if matches.contains_id("group") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("case_sensitive") { + if matches.contains_id("case_sensitive") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("whole_word") { + if matches.contains_id("whole_word") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("regex") { + if matches.contains_id("regex") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("hide_time") { + if matches.contains_id("hide_time") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("autohide_time") { + if matches.contains_id("autohide_time") { return true; } else if let Some(flags) = &config.flags { 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 { - matches.is_present("expanded_on_startup") + matches.contains_id("expanded_on_startup") || config .flags .as_ref() @@ -767,7 +768,7 @@ fn get_expanded_on_startup(matches: &ArgMatches, config: &Config) -> bool { fn get_default_widget_and_count( matches: &ArgMatches, config: &Config, ) -> error::Result<(Option, 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::("default_widget_type") { let parsed_widget = widget_type.parse::()?; if let BottomWidgetType::Empty = parsed_widget { None @@ -789,7 +790,8 @@ fn get_default_widget_and_count( 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::("default_widget_count") + { Some(widget_count.parse::()?) } else if let Some(flags) = &config.flags { flags @@ -815,7 +817,7 @@ fn get_default_widget_and_count( } fn get_disable_click(matches: &ArgMatches, config: &Config) -> bool { - if matches.is_present("disable_click") { + if matches.contains_id("disable_click") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("use_old_network_legend") { + if matches.contains_id("use_old_network_legend") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("hide_table_gap") { + if matches.contains_id("hide_table_gap") { return true; } else if let Some(flags) = &config.flags { 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 matches.is_present("battery") { + if matches.contains_id("battery") { return true; } else if let Some(flags) = &config.flags { 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 { if cfg!(feature = "gpu") { - if matches.is_present("enable_gpu_memory") { + if matches.contains_id("enable_gpu_memory") { return true; } else if let Some(flags) = &config.flags { 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)] fn get_no_write(matches: &ArgMatches, config: &Config) -> bool { - if matches.is_present("no_write") { + if matches.contains_id("no_write") { return true; } else if let Some(flags) = &config.flags { if let Some(no_write) = flags.no_write { @@ -932,7 +934,7 @@ fn get_ignore_list(ignore_list: &Option) -> error::Result error::Result { - if let Some(color) = matches.value_of("color") { + if let Some(color) = matches.get_one::("color") { // Highest priority is always command line flags... return ColourScheme::from_str(color); } 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 { - if matches.is_present("mem_as_value") { + if matches.contains_id("mem_as_value") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("tree") { + if matches.contains_id("tree") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("show_table_scroll_position") { + if matches.contains_id("show_table_scroll_position") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("process_command") { + if matches.contains_id("process_command") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("disable_advanced_kill") { + if matches.contains_id("disable_advanced_kill") { return true; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("network_use_bytes") { + if matches.contains_id("network_use_bytes") { return DataUnit::Byte; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("network_use_log") { + if matches.contains_id("network_use_log") { return AxisScaling::Log; } else if let Some(flags) = &config.flags { 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 { - if matches.is_present("network_use_binary_prefix") { + if matches.contains_id("network_use_binary_prefix") { return true; } else if let Some(flags) = &config.flags { 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 { 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::("retention") { humantime::parse_duration(retention) .map(|dur| dur.as_millis() as u64) .map_err(|err| BottomError::ConfigError(format!("invalid retention duration: {err:?}")))