Skip to content

Commit 5908b1b

Browse files
authored
Merge pull request #5 from andygeorge/ttytm/main
Ttytm/main
2 parents f5e6ee4 + c933ab0 commit 5908b1b

16 files changed

+110
-115
lines changed

Cargo.lock

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ clap = { version = "4.5", default-features = false, features = [
2626
"error-context",
2727
"suggestions",
2828
] }
29-
directories = "5.0"
3029
dialoguer = { version = "0.11", default-features = false }
30+
dirs = "5.0"
3131
futures = "0.3"
3232
optional_struct = "0.5"
3333
regex = { version = "1.10" }

README.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ww
1+
# 🦀 `ww`
22

33
[![][ci_shield]](https://github.com/andygeorge/ww/actions/workflows/ci.yml?query=branch%3Amain)
44
[![][last_commit_shield]](https://github.com/andygeorge/ww/commits/main)
@@ -141,7 +141,6 @@ Win: `%USERPROFILE%\AppData\Roaming\ww\`
141141

142142
Use rusts package manger to install ww.
143143

144-
145144
**From crates.io**
146145

147146
| | |

flake.lock

+25-27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+50-51
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,53 @@
11
{
2-
inputs = {
3-
nixpkgs = {
4-
url = "github:NixOS/nixpkgs/nixpkgs-unstable";
5-
};
2+
inputs = {
3+
utils.url = "github:numtide/flake-utils";
4+
};
5+
outputs =
6+
{
7+
self,
8+
nixpkgs,
9+
utils,
10+
...
11+
}:
12+
utils.lib.eachDefaultSystem (
13+
system:
14+
let
15+
pkgs = import nixpkgs { inherit system; };
16+
ww =
17+
{
18+
lib,
19+
openssl,
20+
pkg-config,
21+
rustPlatform,
22+
}:
23+
rustPlatform.buildRustPackage {
24+
name = "ww";
25+
src = lib.cleanSource ./.;
26+
cargoLock.lockFile = ./Cargo.lock;
27+
nativeBuildInputs = [
28+
pkg-config
29+
rustPlatform.bindgenHook
30+
];
31+
buildInputs = [ openssl ];
32+
checkFlags = [
33+
# connecting to internet does not work in the sandbox
34+
"--skip=modules::location::tests::geolocation_response"
35+
"--skip=modules::localization::tests::translate_string"
36+
];
637

7-
flake-utils = {
8-
url = "github:numtide/flake-utils";
9-
};
10-
};
11-
outputs = inputs @ {
12-
self,
13-
nixpkgs,
14-
flake-utils,
15-
...
16-
}:
17-
flake-utils.lib.eachDefaultSystem (system: let
18-
pkgs = nixpkgs.legacyPackages.${system};
19-
ww = {
20-
lib,
21-
openssl,
22-
pkg-config,
23-
rustPlatform,
24-
}:
25-
rustPlatform.buildRustPackage {
26-
name = "ww";
27-
src = lib.cleanSource ./.;
28-
cargoLock.lockFile = ./Cargo.lock;
29-
nativeBuildInputs = [
30-
pkg-config
31-
rustPlatform.bindgenHook
32-
];
33-
buildInputs = [openssl];
34-
35-
checkFlags = [
36-
# connecting to internet does not work in the sandbox
37-
"--skip=modules::location::tests::geolocation_response"
38-
"--skip=modules::localization::tests::translate_string"
39-
];
40-
41-
meta = with lib; {
42-
license = licenses.mit;
43-
homepage = "https://github.com/andygeorge/ww";
44-
platforms = platforms.all;
45-
};
46-
};
47-
in {
48-
packages.default = pkgs.callPackage ww {};
49-
apps.default = {
50-
type = "app";
51-
program = "${self.outputs.packages.${system}.default}/bin/ww";
52-
};
53-
});
38+
meta = with lib; {
39+
license = licenses.mit;
40+
homepage = "https://github.com/andygeorge/ww";
41+
platforms = platforms.all;
42+
};
43+
};
44+
in
45+
{
46+
packages.default = pkgs.callPackage ww { };
47+
apps.default = {
48+
type = "app";
49+
program = "${self.outputs.packages.${system}.default}/bin/ww";
50+
};
51+
}
52+
);
5453
}

locales/generate.sh

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
(printf "# This file was generated from the localedata in 'github.com/chronotope/pure-rust-locales'.\n"; \
3+
curl https://api.github.com/repos/chronotope/pure-rust-locales/contents/localedata/locales | jq -r '.[].name') \
4+
| sed '/^translit_/d; /^iso/d; s/@/_/g' \
5+
> "$(dirname "$(realpath "$0")")/pure-rust-locales.txt"

locales/pure-rust-locales.txt

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# This file was auto generated from the available localedata in pure-rust-locales.git.
2-
1+
# This file was generated from the localedata in 'github.com/chronotope/pure-rust-locales'.
32
POSIX
43
aa_DJ
54
aa_ER

src/modules/api.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ pub trait Api {
22
fn assemble(&self) -> String;
33
}
44

5-
impl<'a> Api for Box<dyn 'a + Api> {
5+
impl Api for Box<dyn '_ + Api> {
66
fn assemble(&self) -> String {
77
self.as_ref().assemble()
88
}
@@ -54,7 +54,7 @@ impl<'a> ApiQuery<'a> {
5454
}
5555
}
5656

57-
impl<'a> Default for ApiQuery<'a> {
57+
impl Default for ApiQuery<'_> {
5858
fn default() -> Self {
5959
Self {
6060
api: ApiName::OpenMeteo,
@@ -81,7 +81,7 @@ pub struct OpenMeteoLocationQuery<'a> {
8181
language: &'a str,
8282
}
8383

84-
impl<'a> Api for OpenMeteoLocationQuery<'a> {
84+
impl Api for OpenMeteoLocationQuery<'_> {
8585
fn assemble(&self) -> String {
8686
format!(
8787
"https://geocoding-api.open-meteo.com/v1/search?name={}&language={}",
@@ -95,7 +95,7 @@ pub struct OpenStreetMapLocationQuery<'a> {
9595
language: &'a str,
9696
}
9797

98-
impl<'a> Api for OpenStreetMapLocationQuery<'a> {
98+
impl Api for OpenStreetMapLocationQuery<'_> {
9999
fn assemble(&self) -> String {
100100
format!(
101101
"https://nominatim.openstreetmap.org/search?q={}&accept-language={}&limit=1&format=jsonv2",

src/modules/args.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, Result};
1+
use anyhow::{bail, Result};
22
use chrono::NaiveDate;
33
use clap::{Parser, ValueEnum};
44
use serde::{Deserialize, Serialize};
@@ -28,11 +28,11 @@ pub struct Cli {
2828
pub language: Option<String>,
2929

3030
/// Save the supplied values as default
31-
#[arg(short, long, action, group = "config_file_action")]
31+
#[arg(short, long, group = "config_file_action")]
3232
pub save: bool,
3333

3434
/// Wipe ww's configuration data
35-
#[arg(short, long, action, group = "config_file_action")]
35+
#[arg(short, long, group = "config_file_action")]
3636
pub reset: bool,
3737
}
3838

@@ -91,8 +91,7 @@ pub enum UnitArg {
9191

9292
fn parse_language_code(s: &str) -> Result<String> {
9393
if s.len() < 2 {
94-
Err(anyhow!("\n The language code must be at least two characters long."))
95-
} else {
96-
Ok(s.to_string())
94+
bail!("\n The language code must be at least two characters long.")
9795
}
96+
Ok(s.to_string())
9897
}

src/modules/config.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use anyhow::Result;
22
use dialoguer::console::style;
3-
use directories::ProjectDirs;
43
use optional_struct::{optional_struct, Applicable};
54
use ron::{
65
extensions::Extensions,
@@ -90,9 +89,6 @@ impl Config {
9089
}
9190

9291
pub fn get_path() -> PathBuf {
93-
ProjectDirs::from("", "", CONFIG_DIR_NAME)
94-
.unwrap()
95-
.config_dir()
96-
.join(CONFIG_FILE_NAME)
92+
dirs::config_dir().unwrap().join(CONFIG_DIR_NAME).join(CONFIG_FILE_NAME)
9793
}
9894
}

src/modules/display/current.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ mod tests {
261261
│⁰⁰˙⁰⁰ ⁰³˙⁰⁰ ⁰⁶˙⁰⁰ ⁰⁹˙⁰⁰ ¹²˙⁰⁰ ¹⁵˙⁰⁰ ¹⁸˙⁰⁰ ²¹˙⁰⁰ │
262262
╰────────────────────────────────────────────────────────────────────────╯";
263263

264-
let (lines, _) = prep(&test_product, &test_params, true).unwrap();
264+
let (lines, _) = prep(test_product, test_params, true).unwrap();
265265
let have = strip_ansi_escapes::strip_str(lines.join("\n"));
266266
assert_eq!(want, have);
267267
}

src/modules/display/utils.rs

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub mod common_tests {
8383
pub static TEST_PRODUCT: OnceLock<Product> = OnceLock::new();
8484
pub static TEST_PARAMS: OnceLock<Params> = OnceLock::new();
8585

86+
#[allow(clippy::too_many_lines)]
8687
pub fn init_test_product() -> Product<'static> {
8788
Product {
8889
address: String::from("Berlin, Germany"),

src/modules/display/weathercode.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, Result};
1+
use anyhow::{bail, Result};
22

33
use crate::modules::localization::WeatherCodeLocales;
44

@@ -38,7 +38,7 @@ impl WeatherCode {
3838
95 => (&t.thunderstorm, if is_night { '' } else { '' }),
3939
96 => (&t.thunderstorm_slight_hail, if is_night { '' } else { '' }),
4040
99 => (&t.thunderstorm_heavy_hail, if is_night { '' } else { '' }),
41-
_ => return Err(anyhow!("Unknown weather code")),
41+
_ => bail!("Unknown weather code"),
4242
};
4343

4444
Ok(Self {

src/modules/display/wind.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use anyhow::{anyhow, Result};
1+
use anyhow::{bail, Result};
22
use strum_macros::Display;
33

44
#[derive(Display)]
@@ -24,7 +24,7 @@ impl WindDirection {
2424
wd if (202.5..247.5).contains(&wd) => Self::SW,
2525
wd if (247.5..292.5).contains(&wd) => Self::W,
2626
wd if (292.5..337.5).contains(&wd) => Self::NW,
27-
_ => return Err(anyhow!("Wind from another dimension")),
27+
_ => bail!("Wind from another dimension"),
2828
};
2929

3030
Ok(direction)

src/modules/localization.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use anyhow::{Context, Result};
22
use chrono::{Local, NaiveDate};
3-
use directories::ProjectDirs;
43
use futures::{stream::FuturesOrdered, TryStreamExt};
54
use optional_struct::{optional_struct, Applicable};
65
use reqwest::Url;
@@ -243,9 +242,9 @@ impl Locales {
243242
}
244243

245244
pub fn get_path(lang: &str) -> PathBuf {
246-
ProjectDirs::from("", "", crate::modules::config::CONFIG_DIR_NAME)
245+
dirs::config_dir()
247246
.unwrap()
248-
.config_dir()
247+
.join(super::config::CONFIG_DIR_NAME)
249248
.join("locales")
250249
.join(format!("{lang}.json"))
251250
}

0 commit comments

Comments
 (0)