-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: split CLI and library into separate crates
To allow for using the core business logic here outside of the CLI (eg. integration with `-Zscript`).
- Loading branch information
1 parent
162ef19
commit f7b26bc
Showing
19 changed files
with
478 additions
and
512 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,21 @@ | ||
[package] | ||
name = "conditions" | ||
[workspace] | ||
resolver = "2" | ||
|
||
members = ["cli", "lib"] | ||
|
||
[workspace.package] | ||
version = "0.2.0" | ||
edition = "2021" | ||
authors = ["John Allen <[email protected]>"] | ||
repository = "https://github.com/johnallen3d/conditions" | ||
authors = ["John Allen <[email protected]"] | ||
homepage = "https://github.com/johnallen3d/conditions" | ||
repository = "https://github.com/johnallen3d/mp-cli.git" | ||
description = "Fetch basic weather conditions for current or specified location" | ||
keywords = ["weather"] | ||
categories = ["command-line-utilities"] | ||
readme = "README.md" | ||
|
||
license = "MIT" | ||
|
||
[dependencies] | ||
clap = { version = "4.4.13", features = ["derive"] } | ||
confy = "0.5.1" | ||
env_logger = "0.10.1" | ||
eyre = "0.6.11" | ||
lazy_static = "1.4.0" | ||
log = "0.4.20" | ||
rustls = "0.21.9" | ||
[workspace.dependencies] | ||
eyre = "0.6.8" | ||
serde = { version = "1", features = ["derive"] } | ||
thiserror = "1.0.56" | ||
ureq = { version = "2.9.1", features = ["json"] } | ||
sqlx = { version = "0.7", features = ["macros", "runtime-tokio", "sqlite"] } | ||
tokio = { version = "1.34", features = ["macros"] } | ||
|
||
[dev-dependencies] | ||
tempfile = "3.8.1" | ||
thiserror = "1.0.50" | ||
tokio = { version = "1.33", features = ["macros"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
[package] | ||
name = "conditions-cli" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
authors = { workspace = true } | ||
homepage = { workspace = true } | ||
repository = { workspace = true } | ||
description = "CLI tootl to fetch basic weather conditions for current or specified location" | ||
keywords = { workspace = true } | ||
categories = ["command-line-utilities", "weather"] | ||
readme = { workspace = true } | ||
license = { workspace = true } | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
clap = { version = "4.4.8", features = ["derive"] } | ||
conditions = { path = "../lib" } | ||
env_logger = "0.10.0" | ||
eyre = { workspace = true } | ||
log = "0.4.20" | ||
serde = { workspace = true } | ||
serde_json = "1.0.111" | ||
thiserror = { workspace = true } | ||
tokio = { workspace = true } | ||
|
||
[dev-dependencies] | ||
tempfile = "3.8.1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
[package] | ||
name = "conditions" | ||
version = { workspace = true } | ||
edition = { workspace = true } | ||
authors = { workspace = true } | ||
homepage = { workspace = true } | ||
repository = { workspace = true } | ||
description = "Fetch basic weather conditions for current or specified location" | ||
keywords = { workspace = true } | ||
categories = ["weather"] | ||
readme = { workspace = true } | ||
license = { workspace = true } | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
confy = "0.5.1" | ||
eyre = { workspace = true } | ||
lazy_static = "1.4.0" | ||
rustls = "0.22.1" | ||
sqlx = { version = "0.7", features = ["macros", "runtime-tokio", "sqlite"] } | ||
thiserror = { workspace = true } | ||
ureq = { version = "2.8.0", features = ["json"] } | ||
serde = { workspace = true } | ||
tokio = { workspace = true } |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#![deny(clippy::pedantic)] | ||
|
||
use std::fmt; | ||
|
||
use serde::{Deserialize, Deserializer, Serialize}; | ||
|
||
pub(crate) mod api; | ||
pub mod cache; | ||
pub mod conditions; | ||
pub mod config; | ||
pub mod icons; | ||
pub mod location; | ||
mod weather; | ||
|
||
pub use cache::Cache; | ||
pub use conditions::Conditions; | ||
pub use config::Config; | ||
|
||
#[derive(Clone, Copy, Debug, Default, Serialize)] | ||
pub enum Unit { | ||
C, | ||
#[default] | ||
F, | ||
} | ||
|
||
impl Unit { | ||
#[must_use] | ||
pub fn from_char(unit: char) -> Option<Self> { | ||
match unit { | ||
'c' => Some(Self::C), | ||
'f' => Some(Self::F), | ||
_ => None, | ||
} | ||
} | ||
|
||
#[must_use] | ||
pub fn as_char(&self) -> char { | ||
match self { | ||
Unit::C => 'c', | ||
Unit::F => 'f', | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for Unit { | ||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { | ||
let text = match self { | ||
Unit::C => "celsius", | ||
Unit::F => "fahrenheit", | ||
}; | ||
write!(f, "{text}") | ||
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for Unit { | ||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> | ||
where | ||
D: Deserializer<'de>, | ||
{ | ||
let s = String::deserialize(deserializer)?.to_lowercase(); | ||
match s.as_str() { | ||
"c" => Ok(Unit::C), | ||
_ => Ok(Unit::F), | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file was deleted.
Oops, something went wrong.