Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: rename flags.enable_gpu to flags.disable_gpu (false by default) #1559

Merged
merged 1 commit into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion schema/nightly/bottom.json
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
"null"
]
},
"enable_gpu": {
"disable_gpu": {
"type": [
"boolean",
"null"
Expand Down
4 changes: 2 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ pub(crate) const CONFIG_TEXT: &str = r#"# This is a default config file for bott
#network_use_log = false
# Hides advanced options to stop a process on Unix-like systems.
#disable_advanced_kill = false
# Shows GPU(s) information
#enable_gpu = false
# Hide GPU(s) information
#disable_gpu = false
# Shows cache and buffer memory
#enable_cache_memory = false
# How much data is stored at once in terms of time.
Expand Down
21 changes: 11 additions & 10 deletions src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -806,19 +806,20 @@ fn get_use_battery(args: &BottomArgs, config: &Config) -> bool {
false
}

#[allow(unused_variables)]
#[cfg(feature = "gpu")]
fn get_enable_gpu(args: &BottomArgs, config: &Config) -> bool {
#[cfg(feature = "gpu")]
{
if args.gpu.enable_gpu {
return true;
} else if let Some(flags) = &config.flags {
if let Some(enable_gpu) = flags.enable_gpu {
return enable_gpu;
}
}
if args.gpu.disable_gpu {
return false;
}
!config
.flags
.as_ref()
.and_then(|f| f.disable_gpu)
.unwrap_or(false)
}

#[cfg(not(feature = "gpu"))]
fn get_enable_gpu(_: &BottomArgs, _: &Config) -> bool {
false
}

Expand Down
4 changes: 2 additions & 2 deletions src/options/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,8 +520,8 @@ pub struct BatteryArgs {
#[derive(Args, Clone, Debug, Default)]
#[command(next_help_heading = "GPU Options", rename_all = "snake_case")]
pub struct GpuArgs {
#[arg(long, action = ArgAction::SetTrue, help = "Enable collecting and displaying GPU usage.")]
pub enable_gpu: bool,
#[arg(long, action = ArgAction::SetTrue, help = "Disable collecting and displaying GPU usage.")]
pub disable_gpu: bool,
}

/// Style arguments/config options.
Expand Down
2 changes: 1 addition & 1 deletion src/options/config/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub(crate) struct FlagConfig {
pub(crate) network_use_bytes: Option<bool>,
pub(crate) network_use_log: Option<bool>,
pub(crate) network_use_binary_prefix: Option<bool>,
pub(crate) enable_gpu: Option<bool>,
pub(crate) disable_gpu: Option<bool>,
pub(crate) enable_cache_memory: Option<bool>,
pub(crate) retention: Option<StringOrNum>,
pub(crate) average_cpu_row: Option<bool>,
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/arg_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ fn test_battery_flag() {
#[cfg_attr(feature = "gpu", ignore)]
fn test_gpu_flag() {
no_cfg_btm_command()
.arg("--enable_gpu")
.arg("--disable_gpu")
.assert()
.failure()
.stderr(predicate::str::contains(
"unexpected argument '--enable_gpu' found",
"unexpected argument '--disable_gpu' found",
));
}

Expand Down