-
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.
- Loading branch information
Showing
11 changed files
with
104 additions
and
12 deletions.
There are no files selected for viewing
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 @@ | ||
# autoi18n-cli |
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,31 @@ | ||
#[derive(Debug)] | ||
pub enum ConfigError { | ||
IoError(std::io::Error), | ||
ParseError(serde_json::Error), | ||
} | ||
|
||
impl std::error::Error for ConfigError {} | ||
|
||
impl core::fmt::Display for ConfigError { | ||
#[inline] | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::IoError(e) => e.fmt(f), | ||
Self::ParseError(e) => e.fmt(f), | ||
} | ||
} | ||
} | ||
|
||
impl From<std::io::Error> for ConfigError { | ||
#[inline] | ||
fn from(value: std::io::Error) -> Self { | ||
Self::IoError(value) | ||
} | ||
} | ||
|
||
impl From<serde_json::Error> for ConfigError { | ||
#[inline] | ||
fn from(value: serde_json::Error) -> Self { | ||
Self::ParseError(value) | ||
} | ||
} |
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,14 +1,29 @@ | ||
pub fn add(left: u64, right: u64) -> u64 { | ||
left + right | ||
use error::ConfigError; | ||
|
||
pub mod error; | ||
|
||
#[derive(serde::Serialize, serde::Deserialize)] | ||
pub struct CliConfig { | ||
#[serde(rename = "$schema", default = "CliConfig::default_schema_location")] | ||
pub schema: String, | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
impl CliConfig { | ||
#[inline] | ||
pub fn load(path: impl AsRef<std::path::Path>) -> Result<Self, ConfigError> { | ||
let content = std::fs::read_to_string(path)?; | ||
|
||
let parsed = serde_json::from_str::<Self>(&content)?; | ||
|
||
Ok(parsed) | ||
} | ||
|
||
#[inline] | ||
fn default_schema_location() -> String { | ||
let package_version = env!("CARGO_PKG_VERSION"); | ||
|
||
#[test] | ||
fn it_works() { | ||
let result = add(2, 2); | ||
assert_eq!(result, 4); | ||
format!( | ||
"https://raw.githubusercontent.com/autoi18n/cli/main/schemas/v{package_version}/autoi18n.schema.json" | ||
) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -19,3 +19,4 @@ license = false | |
eula = false | ||
|
||
[dependencies] | ||
autoi18n-config = { workspace = true } |
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,22 @@ | ||
#[derive(Debug)] | ||
pub enum CliError { | ||
Config(autoi18n_config::error::ConfigError), | ||
} | ||
|
||
impl std::error::Error for CliError {} | ||
|
||
impl core::fmt::Display for CliError { | ||
#[inline] | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
match self { | ||
Self::Config(e) => e.fmt(f), | ||
} | ||
} | ||
} | ||
|
||
impl From<autoi18n_config::error::ConfigError> for CliError { | ||
#[inline] | ||
fn from(value: autoi18n_config::error::ConfigError) -> Self { | ||
Self::Config(value) | ||
} | ||
} |
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,3 +1,16 @@ | ||
use autoi18n_config::CliConfig; | ||
|
||
mod error; | ||
|
||
#[inline] | ||
fn _main() -> Result<(), error::CliError> { | ||
let _config = CliConfig::load("autoi18n.json")?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
println!("Hello, world!"); | ||
if let Err(error) = _main() { | ||
eprintln!("{error}"); | ||
} | ||
} |
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