Skip to content

Commit

Permalink
chore: 🎨 Format the code
Browse files Browse the repository at this point in the history
  • Loading branch information
KAIYOHUGO committed Jun 19, 2023
1 parent 01b6f6f commit 92fff85
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/fetch_bedrock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub async fn fetch(
.send()
.await?;
for i in page.items {
let Some((lang_id,ext))=i.name.split_once(".") else {
let Some((lang_id,ext))=i.name.split_once('.') else {
continue;
};
if ext != "lang" {
Expand Down
7 changes: 3 additions & 4 deletions src/generate.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::{collections::HashMap, io::Write, path::PathBuf, sync::Arc};
use std::{collections::HashMap, path::PathBuf, sync::Arc};

use crate::{
pack::{pack_addon, Header, Manifest, Module},
parse::{ser_bedrock, TranslateKV},
parse::TranslateKV,
};
use anyhow::{anyhow, Result};
use tokio::{fs, task};
use tokio_util::io::SyncIoBridge;
use tokio::task;

/// output is `Map<bedrock_id,java_id>`
pub fn gen_bedrock_java_id_map(mut bedrock: TranslateKV, java: TranslateKV) -> TranslateKV {
Expand Down
16 changes: 6 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@ mod generate;
mod pack;
mod parse;

use anyhow::{anyhow, Context, Result};
use api::get;
use anyhow::{anyhow, Result};

use clap::Parser;
use generate::gen_output;
use octocrab::params::repos::Reference;
use parse::{des_bedrock, des_en_us_from_java, des_java};

use parse::{des_bedrock, des_java};
use std::{collections::HashMap, path::PathBuf};
use tokio::{fs, io, select, spawn, task, try_join};
use tokio_util::io::SyncIoBridge;
use tokio::{fs, io, task, try_join};

#[derive(Debug, Clone, Parser)]
struct Cli {
Expand Down Expand Up @@ -176,14 +175,11 @@ fn parse_version(version: String) -> Result<[u8; 3]> {
while ret.len() < 3 {
ret.push(0);
}
Ok(ret
.try_into()
.map_err(|_| anyhow!("Version Format Error"))?)
ret.try_into().map_err(|_| anyhow!("Version Format Error"))
}

#[cfg(test)]
mod tests {
use super::*;

#[tokio::test]
async fn test_name() {
Expand Down
13 changes: 3 additions & 10 deletions src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::{
collections::HashMap,
io::{Cursor, Read, Write},
};
use tokio::io::{self, AsyncBufRead, AsyncBufReadExt, AsyncReadExt, AsyncWriteExt};
use tokio::io::{AsyncBufRead, AsyncBufReadExt, AsyncReadExt};
use zip::ZipArchive;

pub type TranslateKV = HashMap<String, String>;
Expand All @@ -22,14 +22,14 @@ pub async fn des_bedrock(reader: impl AsyncBufReadExt + Unpin) -> Result<Transla
let mut lines = reader.lines();

while let Some(line) = lines.next_line().await? {
let text = if let Some((text, _comment)) = line.split_once("#") {
let text = if let Some((text, _comment)) = line.split_once('#') {
text
} else {
&line
};
// ignore BOM
let text = text
.trim_start_matches("\u{feff}")
.trim_start_matches('\u{feff}')
.trim_start()
.trim_end_matches('\t');
if text.is_empty() {
Expand All @@ -45,13 +45,6 @@ pub async fn des_bedrock(reader: impl AsyncBufReadExt + Unpin) -> Result<Transla
Ok(kv)
}

pub async fn ser_bedrock(writer: &mut (impl AsyncWriteExt + Unpin), kv: TranslateKV) -> Result<()> {
for (k, v) in kv {
writer.write_all(format!("{k}={v}\n").as_bytes()).await?;
}
Ok(())
}

pub fn sync_ser_bedrock(writer: &mut impl Write, kv: TranslateKV) -> Result<()> {
for (k, v) in kv {
writeln!(writer, "{k}={v}")?;
Expand Down

0 comments on commit 92fff85

Please sign in to comment.