Skip to content

Commit

Permalink
feat: select project on init (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
hougesen authored Sep 25, 2024
1 parent 5575afc commit 35ecd68
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 19 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

#### Unreleased

- refactor: rename project [`#24`](https://github.com/i18nhero/cli/pull/24)
- feat: add flag for saving missing translations [`#23`](https://github.com/i18nhero/cli/pull/23)
- feat(cli): json5 output [`#19`](https://github.com/i18nhero/cli/pull/19)
- feat: generate yml output [`#18`](https://github.com/i18nhero/cli/pull/18)
Expand Down
124 changes: 124 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ serde = { version = "1.0.209", features = ["derive"] }
serde_json = "1.0.128"
serde_yml = "0.0.12"
tempfile = "3.12.0"
tokio = { version = "1.40.0", features = ["full"] }

# Config for 'cargo dist'
[workspace.metadata.dist]
Expand Down
8 changes: 7 additions & 1 deletion i18nhero.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
{
"$schema": "https://raw.githubusercontent.com/i18nhero/cli/main/schemas/v0.0.0/i18nhero.schema.json"
"$schema": "https://raw.githubusercontent.com/i18nhero/cli/main/schemas/v0.0.0/i18nhero.schema.json",
"project_id": "66da3bc6de9d3506120c0a87",
"output": {
"path": "lang",
"format": "json",
"save_missing_values": false
}
}
11 changes: 9 additions & 2 deletions packages/i18nhero-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::str::FromStr;

use error::ConfigError;
use std::str::FromStr;

pub mod error;

Expand Down Expand Up @@ -84,6 +83,14 @@ impl Default for CliConfig {
}

impl CliConfig {
#[inline]
pub fn new(project_id: String) -> Self {
Self {
project_id,
..Default::default()
}
}

#[inline]
pub fn load(path: impl AsRef<std::path::Path>) -> Result<Self, ConfigError> {
let content = std::fs::read_to_string(path)?;
Expand Down
5 changes: 4 additions & 1 deletion packages/i18nhero/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ i18nhero-config = { workspace = true }
clap = { workspace = true }
clap_complete = { workspace = true }
json5 = { workspace = true }
reqwest = { workspace = true }
reqwest.workspace = true
serde = { workspace = true }
serde_json = { workspace = true }
serde_yml = { workspace = true }
dialoguer = "0.11.0"
console = "0.15.8"
tokio = { workspace = true }
9 changes: 9 additions & 0 deletions packages/i18nhero/src/auth/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::error::CliError;

pub async fn get_api_key() -> Result<String, CliError> {
// TODO:

let api_key = "66d7828c3c19bf6163ac150a".to_owned();

Ok(api_key)
}
3 changes: 3 additions & 0 deletions packages/i18nhero/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ use clap::Args;
pub struct InitCommandArguments {
#[arg(long, default_value_t = false)]
pub overwrite: bool,

#[arg(long, hide = true)]
pub api_host: Option<String>,
}
9 changes: 9 additions & 0 deletions packages/i18nhero/src/error/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ pub enum CliError {
Reqwest(reqwest::Error),
ConfigAlreadyExists,
MissingProjectId,
NoConnectedOrganizations,
NoAvailableProjects((String, String)),
}

impl std::error::Error for CliError {}
Expand All @@ -25,6 +27,13 @@ impl core::fmt::Display for CliError {

Self::ConfigAlreadyExists => write!(f, "A configuration file already exists"),
Self::MissingProjectId => write!(f, "project_id must be set in config"),
Self::NoConnectedOrganizations => {
write!(f, "You do not have development access to any organizations")
}
Self::NoAvailableProjects((organization_title, organization_id)) => write!(
f,
"You do not have development access to any projects for {organization_title} ({organization_id})"
),
}
}
}
Expand Down
Loading

0 comments on commit 35ecd68

Please sign in to comment.