Skip to content

Commit a95d433

Browse files
committed
♻️ move greeting to gui config table
- this change is related to the recent implementation of the gui style table, which access is restricted to the config file - the greeting message is not considered so important that it has to be switched on and off quickly via args - this results in less bloated args
1 parent 6ca6d0c commit a95d433

File tree

6 files changed

+5
-64
lines changed

6 files changed

+5
-64
lines changed

src/main.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ async fn main() -> Result<()> {
1515

1616
let product = run(&params).await?;
1717
product
18-
.render(
19-
&params.forecast,
20-
&params.units,
21-
&params.gui,
22-
params.greeting,
23-
&params.language,
24-
)
18+
.render(&params.forecast, &params.units, &params.gui, &params.language)
2519
.await?;
2620

2721
config.handle_next(args, params).await?;

src/modules/args.rs

-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// use clap::{Args, Parser, Subcommand, ValueEnum};
21
use clap::{Parser, ValueEnum};
32
use serde::{Deserialize, Serialize};
43
use strum_macros::AsRefStr;
@@ -21,10 +20,6 @@ pub struct Cli {
2120
#[arg(short, long, global = true)]
2221
pub language: Option<String>,
2322

24-
/// Toggle greeting message
25-
#[arg(short, long, action, hide = true)]
26-
pub greeting: bool,
27-
2823
/// Save the supplied values as default
2924
#[arg(short, long, action, group = "config_file_action")]
3025
pub save: bool,

src/modules/config.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use crate::{
1212
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
1313
pub struct Config {
1414
pub address: Option<String>,
15-
pub greeting: Option<bool>,
1615
pub language: Option<String>,
1716
pub forecast: Option<Vec<Forecast>>,
1817
pub units: Option<Units>,
@@ -24,7 +23,6 @@ impl Default for Config {
2423
Self {
2524
address: None,
2625
forecast: None,
27-
greeting: Some(true),
2826
language: Some("en".to_string()),
2927
units: Some(Units::default()),
3028
gui: Some(Gui::default()),
@@ -35,12 +33,14 @@ impl Default for Config {
3533
#[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
3634
pub struct Gui {
3735
pub border: Option<BorderVariant>,
36+
pub greeting: Option<bool>,
3837
}
3938

4039
impl Default for Gui {
4140
fn default() -> Self {
4241
Self {
4342
border: Some(BorderVariant::default()),
43+
greeting: Some(true),
4444
}
4545
}
4646
}
@@ -57,7 +57,6 @@ impl Config {
5757
} else {
5858
Some(params.address)
5959
},
60-
greeting: Some(params.greeting),
6160
language: Some(params.language),
6261
forecast: if !params.forecast.is_empty() {
6362
Some(params.forecast)

src/modules/display.rs

+2-9
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,8 @@ pub struct Product {
2626
pub const MIN_WIDTH: usize = 34;
2727

2828
impl Product {
29-
pub async fn render(
30-
&self,
31-
forecast: &[ForecastParams],
32-
units: &Units,
33-
gui: &Gui,
34-
include_greeting: bool,
35-
lang: &str,
36-
) -> Result<()> {
37-
greeting::render(include_greeting, lang).await?;
29+
pub async fn render(&self, forecast: &[ForecastParams], units: &Units, gui: &Gui, lang: &str) -> Result<()> {
30+
greeting::render(gui.greeting.unwrap_or_else(|| Gui::default().greeting.unwrap()), lang).await?;
3831

3932
if !forecast.is_empty() {
4033
Forecast::render(self, forecast, units, &gui.border.unwrap_or_default(), lang).await?;

src/modules/params.rs

-5
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,12 @@ use self::units::Units;
99

1010
mod address;
1111
pub mod forecast;
12-
mod greeting;
1312
mod language;
1413
pub mod units;
1514

1615
pub struct Params {
1716
pub address: String,
1817
pub units: Units,
19-
pub greeting: bool,
2018
pub language: String,
2119
pub forecast: Vec<Forecast>,
2220
pub gui: Gui,
@@ -47,13 +45,10 @@ impl Params {
4745

4846
let gui = config.gui.unwrap_or_default();
4947

50-
let greeting = greeting::get(args.greeting, config.greeting)?;
51-
5248
Ok(Params {
5349
address,
5450
units,
5551
language,
56-
greeting,
5752
forecast,
5853
gui,
5954
})

src/modules/params/greeting.rs

-35
This file was deleted.

0 commit comments

Comments
 (0)