summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClementTsang <34804052+ClementTsang@users.noreply.github.com>2024-01-27 05:28:57 -0500
committerClementTsang <34804052+ClementTsang@users.noreply.github.com>2024-02-19 20:08:53 -0500
commit7ffc497f3f1e4c270778c23f64b093f4a5cdc14b (patch)
treeb0a6498405a3d3f1a5c98796469b4002be19452f
parent155d8a37e9facc3531ff9436be9ef504a0ad6a85 (diff)
unify new args with new config
-rw-r--r--Cargo.toml1
-rw-r--r--src/options/args.rs60
-rw-r--r--src/options/config/battery.rs5
-rw-r--r--src/options/config/cpu.rs6
-rw-r--r--src/options/config/general.rs27
-rw-r--r--src/options/config/gpu.rs6
-rw-r--r--src/options/config/memory.rs6
-rw-r--r--src/options/config/network.rs16
-rw-r--r--src/options/config/process.rs22
-rw-r--r--src/options/config/style.rs6
-rw-r--r--src/options/config/temperature.rs5
11 files changed, 81 insertions, 79 deletions
diff --git a/Cargo.toml b/Cargo.toml
index 78172893..7ee49bd2 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -143,6 +143,7 @@ clap_complete_fig = "4.5.0"
clap_complete_nushell = "4.5.0"
clap_mangen = "0.2.20"
indoc = "2.0.4"
+serde = { version = "=1.0.196", features = ["derive"] }
[package.metadata.deb]
section = "utility"
diff --git a/src/options/args.rs b/src/options/args.rs
index d2ee7518..4203e270 100644
--- a/src/options/args.rs
+++ b/src/options/args.rs
@@ -9,6 +9,23 @@ use std::cmp::Ordering;
use clap::*;
use indoc::indoc;
+use serde::Deserialize;
+
+#[derive(Clone, Debug, Deserialize)]
+#[serde(untagged)]
+pub(crate) enum StringOrNum {
+ String(String),
+ Num(u64),
+}
+
+impl From<&str> for StringOrNum {
+ fn from(value: &str) -> Self {
+ match value.parse::<u64>() {
+ Ok(parsed) => StringOrNum::Num(parsed),
+ Err(_) => StringOrNum::String(value.to_owned()),
+ }
+ }
+}
/// Returns an [`Ordering`] for two [`Arg`] values.
///
@@ -68,7 +85,9 @@ const VERSION: &str = match option_env!("NIGHTLY_VERSION") {
help_template = TEMPLATE,
override_usage = USAGE,
)]
-pub(crate) struct Args {
+
+/// Represents the arguments that can be passed in to bottom.
+pub struct Args {
#[command(flatten)]
pub(crate) general_args: GeneralArgs,
@@ -82,7 +101,7 @@ pub(crate) struct Args {
pub(crate) cpu_args: CpuArgs,
#[command(flatten)]
- pub(crate) mem_args: MemArgs,
+ pub(crate) mem_args: MemoryArgs,
#[command(flatten)]
pub(crate) network_args: NetworkArgs,
@@ -102,7 +121,7 @@ pub(crate) struct Args {
pub(crate) other_args: OtherArgs,
}
-#[derive(Args, Clone, Debug)]
+#[derive(Args, Clone, Debug, Default, Deserialize)]
#[command(next_help_heading = "General Options")]
pub(crate) struct GeneralArgs {
#[arg(
@@ -127,9 +146,10 @@ pub(crate) struct GeneralArgs {
value_name = "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, a default config file is created at the path."
+ If it doesn't exist, a default config file is created at the path. If no path is provided,
+ the default config location will be used."
)]
- pub(crate) config_location: String,
+ pub(crate) config_location: Option<String>,
#[arg(
short = 't',
@@ -139,7 +159,7 @@ pub(crate) struct GeneralArgs {
long_help = "The default time value for graphs. Takes a number in milliseconds or a human \
duration (e.g. 60s). The minimum time is 30s, and the default is 60s."
)]
- pub(crate) default_time_value: String,
+ pub(crate) default_time_value: Option<StringOrNum>,
// TODO: Charts are broken in the manpage
#[arg(
@@ -202,7 +222,7 @@ pub(crate) struct GeneralArgs {
Setting '--default_widget_type Temp' will make the temperature widget selected by default."
}
)]
- pub(crate) default_widget_type: String,
+ pub(crate) default_widget_type: Option<String>,
#[arg(
long,
@@ -246,7 +266,7 @@ pub(crate) struct GeneralArgs {
(e.g. 5s). The minimum is 250ms, and defaults to 1000ms. Smaller values may result in higher \
system usage by bottom."
)]
- pub(crate) rate: String,
+ pub(crate) rate: Option<StringOrNum>,
#[arg(
long,
@@ -256,7 +276,7 @@ pub(crate) struct GeneralArgs {
human-readable duration (e.g. 20m), with a minimum of 1 minute. Note that higher values \
will take up more memory. Defaults to 10 minutes."
)]
- pub(crate) retention: String,
+ pub(crate) retention: Option<StringOrNum>,
#[arg(
long,
@@ -273,10 +293,10 @@ pub(crate) struct GeneralArgs {
long_help = "The amount of time changed when zooming in/out. Takes a number in milliseconds or a \
human-readable duration (e.g. 30s). The minimum is 1s, and defaults to 15s."
)]
- pub(crate) time_delta: String,
+ pub(crate) time_delta: Option<StringOrNum>,
}
-#[derive(Args, Clone, Debug)]
+#[derive(Args, Clone, Debug, Default, Deserialize)]
#[command(next_help_heading = "Process Options")]
pub(crate) struct ProcessArgs {
#[arg(
@@ -341,7 +361,7 @@ pub(crate) struct ProcessArgs {
pub(crate) whole_word: bool,
}
-#[derive(Args, Clone, Debug)]
+#[derive(Args, Clone, Debug, Default, Deserialize)]
#[command(next_help_heading = "Temperature Options")]
#[group(multiple = false)]
pub(crate) struct TemperatureArgs {
@@ -371,7 +391,7 @@ pub(crate) struct TemperatureArgs {
pub(crate) kelvin: bool,
}
-#[derive(Args, Clone, Debug)]
+#[derive(Args, Clone, Debug, Default, Deserialize)]
#[command(next_help_heading = "CPU Options")]
pub(crate) struct CpuArgs {
#[arg(
@@ -392,9 +412,9 @@ pub(crate) struct CpuArgs {
pub(crate) left_legend: bool,
}
-#[derive(Args, Clone, Debug)]
+#[derive(Args, Clone, Debug, Default, Deserialize)]
#[command(next_help_heading = "Memory Options")]
-pub(crate) struct MemArgs {
+pub(crate) struct MemoryArgs {
#[cfg(not(target_os = "windows"))]
#[arg(
long,
@@ -410,7 +430,7 @@ pub(crate) struct MemArgs {
pub(crate) mem_as_value: bool,
}
-#[derive(Args, Clone, Debug)]
+#[derive(Args, Clone, Debug, Default, Deserialize)]
#[command(next_help_heading = "Network Options")]
pub(crate) struct NetworkArgs {
#[arg(
@@ -444,7 +464,7 @@ pub(crate) struct NetworkArgs {
}
#[cfg(feature = "battery")]
-#[derive(Args, Clone, Debug)]
+#[derive(Args, Clone, Debug, Default, Deserialize)]
#[command(next_help_heading = "Battery Options")]
pub(crate) struct BatteryArgs {
#[arg(
@@ -458,14 +478,14 @@ pub(crate) struct BatteryArgs {
}
#[cfg(feature = "gpu")]
-#[derive(Args, Clone, Debug)]
+#[derive(Args, Clone, Debug, Default, Deserialize)]
#[command(next_help_heading = "GPU Options")]
pub(crate) struct GpuArgs {
#[arg(long, help = "Enables collecting and displaying GPU usage.")]
pub(crate) enable_gpu: bool,
}
-#[derive(Args, Clone, Debug)]
+#[derive(Args, Clone, Debug, Default, Deserialize)]
#[command(next_help_heading = "Style Options")]
pub(crate) struct StyleArgs {
#[arg(
@@ -493,7 +513,7 @@ pub(crate) struct StyleArgs {
- nord-light (nord but adjusted for lighter backgrounds)"
}
)]
- pub(crate) color: String,
+ pub(crate) color: Option<String>,
}
#[derive(Args, Clone, Debug)]
diff --git a/src/options/config/battery.rs b/src/options/config/battery.rs
index 4f778cff..27798592 100644
--- a/src/options/config/battery.rs
+++ b/src/options/config/battery.rs
@@ -1,6 +1,9 @@
use serde::Deserialize;
+use crate::args::BatteryArgs;
+
+#[cfg(feature = "battery")]
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct BatteryOptions {
- pub(crate) battery: Option<bool>,
+ pub(crate) args: BatteryArgs,
}
diff --git a/src/options/config/cpu.rs b/src/options/config/cpu.rs
index e6bec93c..71199704 100644
--- a/src/options/config/cpu.rs
+++ b/src/options/config/cpu.rs
@@ -1,5 +1,7 @@
use serde::Deserialize;
+use crate::args::CpuArgs;
+
/// The default selection of the CPU widget. If the given selection is invalid, we will fall back to all.
#[derive(Clone, Copy, Debug, Default, Deserialize)]
#[serde(rename_all = "lowercase")]
@@ -14,8 +16,8 @@ pub enum CpuDefault {
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct CpuConfig {
- #[serde(default)]
- pub(crate) hide_avg_cpu: bool,
+ #[serde(flatten)]
+ pub(crate) args: CpuArgs,
#[serde(default)]
pub(crate) default: CpuDefault,
}
diff --git a/src/options/config/general.rs b/src/options/config/general.rs
index e39279ed..6470d24b 100644
--- a/src/options/config/general.rs
+++ b/src/options/config/general.rs
@@ -1,33 +1,12 @@
use clap::ArgMatches;
use serde::Deserialize;
-use super::StringOrNum;
+use crate::args::GeneralArgs;
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct GeneralConfig {
- #[serde(default)]
- pub(crate) autohide_time: bool,
- #[serde(default)]
- pub(crate) basic: bool,
- pub(crate) default_time_value: Option<StringOrNum>,
- pub(crate) default_widget_type: Option<String>,
- #[serde(default)]
- pub(crate) disable_click: bool,
- #[serde(default)]
- pub(crate) dot_marker: bool, // TODO: Support other markers!
- #[serde(default)]
- pub(crate) expanded: bool,
- #[serde(default)]
- pub(crate) hide_table_gap: bool,
- #[serde(default)]
- pub(crate) hide_time: bool, // TODO: Combine with autohide_time
- #[serde(default)]
- pub(crate) left_legend: bool,
- pub(crate) rate: Option<StringOrNum>,
- pub(crate) retention: Option<StringOrNum>,
- #[serde(default)]
- pub(crate) show_table_scroll_position: bool,
- pub(crate) time_delta: Option<StringOrNum>,
+ #[serde(flatten)]
+ pub(crate) args: GeneralArgs,
}
impl GeneralConfig {
diff --git a/src/options/config/gpu.rs b/src/options/config/gpu.rs
index 50f9c50c..cbeb922a 100644
--- a/src/options/config/gpu.rs
+++ b/src/options/config/gpu.rs
@@ -1,6 +1,10 @@
use serde::Deserialize;
+use crate::args::GpuArgs;
+
+#[cfg(feature = "gpu")]
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct GpuOptions {
- pub(crate) enable_gpu: Option<bool>, // TODO: Enable by default instead?
+ #[serde(flatten)]
+ pub(crate) args: GpuArgs,
}
diff --git a/src/options/config/memory.rs b/src/options/config/memory.rs
index 4e180122..c7c6ac8b 100644
--- a/src/options/config/memory.rs
+++ b/src/options/config/memory.rs
@@ -1,7 +1,9 @@
use serde::Deserialize;
+use crate::args::MemoryArgs;
+
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct MemoryConfig {
- pub(crate) mem_as_value: Option<bool>,
- pub(crate) enable_cache_memory: Option<bool>,
+ #[serde(flatten)]
+ pub(crate) args: MemoryArgs,
}
diff --git a/src/options/config/network.rs b/src/options/config/network.rs
index 3eb7bb7b..2bb3d959 100644
--- a/src/options/config/network.rs
+++ b/src/options/config/network.rs
@@ -1,13 +1,13 @@
use serde::Deserialize;
+use crate::args::NetworkArgs;
+
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct NetworkConfig {
- #[serde(default)]
- pub(crate) network_use_bytes: bool,
- #[serde(default)]
- pub(crate) network_use_log: bool,
- #[serde(default)]
- pub(crate) network_use_binary_prefix: bool,
- #[serde(default)]
- pub(crate) use_old_network_legend: bool,
+ #[serde(flatten)]
+ pub(crate) args: NetworkArgs,
}
+
+impl NetworkConfig {
+
+} \ No newline at end of file
diff --git a/src/options/config/process.rs b/src/options/config/process.rs
index b677937a..c48ca044 100644
--- a/src/options/config/process.rs
+++ b/src/options/config/process.rs
@@ -1,28 +1,12 @@
use serde::Deserialize;
-use crate::widgets::ProcWidgetColumn;
+use crate::{args::ProcessArgs, widgets::ProcWidgetColumn};
/// Process column settings.
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct ProcessConfig {
- #[serde(default)]
- pub(crate) case_sensitive: bool,
- #[serde(default)]
- pub(crate) current_usage: bool,
- #[serde(default)]
- pub(crate) disable_advanced_kill: bool,
- #[serde(default)]
- pub(crate) group_processes: bool,
- #[serde(default)]
- pub(crate) process_command: bool,
- #[serde(default)]
- pub(crate) regex: bool,
- #[serde(default)]
- pub(crate) tree: bool,
- #[serde(default)]
- pub(crate) unnormalized_cpu: bool,
- #[serde(default)]
- pub(crate) whole_word: bool,
+ #[serde(flatten)]
+ pub(crate) args: ProcessArgs,
pub(crate) columns: Option<Vec<ProcWidgetColumn>>,
}
diff --git a/src/options/config/style.rs b/src/options/config/style.rs
index 5c09ea8e..38d93500 100644
--- a/src/options/config/style.rs
+++ b/src/options/config/style.rs
@@ -3,7 +3,11 @@ pub mod palettes;
use serde::Deserialize;
+use crate::args::StyleArgs;
+
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct StyleConfig {
- pub(crate) color: Option<String>, // TODO: parse enum instead? And how should this react with colour schemes?
+ #[serde(flatten)]
+ pub(crate) args: StyleArgs,
+ // TODO: Maybe also put colours here?
}
diff --git a/src/options/config/temperature.rs b/src/options/config/temperature.rs
index 90e9bb17..1fd6a852 100644
--- a/src/options/config/temperature.rs
+++ b/src/options/config/temperature.rs
@@ -1,6 +1,9 @@
use serde::Deserialize;
+use crate::args::TemperatureArgs;
+
#[derive(Clone, Debug, Default, Deserialize)]
pub(crate) struct TemperatureConfig {
- pub(crate) temperature_type: Option<String>,
+ #[serde(flatten)]
+ pub(crate) args: TemperatureArgs,
}