Remove remaining warnings
This commit is contained in:
parent
a07ecae04a
commit
254a2aefd7
@ -1,6 +1,4 @@
|
||||
use std::{
|
||||
fmt, io::{BufReader, Read, Write}, path::PathBuf, process::Command
|
||||
};
|
||||
use std::{fmt, path::PathBuf};
|
||||
|
||||
use clap::{Parser, Subcommand};
|
||||
|
||||
@ -24,9 +22,9 @@ enum Commands {
|
||||
/// Edit, potentially creating, a key
|
||||
EditKey {
|
||||
#[arg(short, long)]
|
||||
name: String,
|
||||
key: String,
|
||||
#[arg(short, long)]
|
||||
locale: String,
|
||||
locale: Option<String>,
|
||||
},
|
||||
/// List al keys in the database
|
||||
ListKeys,
|
||||
@ -41,6 +39,8 @@ enum Commands {
|
||||
#[arg(short, long)]
|
||||
format: String,
|
||||
#[arg(short, long)]
|
||||
file: String,
|
||||
#[arg(short, long)]
|
||||
locale: Option<String>,
|
||||
},
|
||||
Report,
|
||||
@ -50,7 +50,6 @@ enum Commands {
|
||||
struct Config {
|
||||
db_path: PathBuf,
|
||||
base_locale: LanguageIdentifier,
|
||||
locales: Vec<LanguageIdentifier>,
|
||||
}
|
||||
|
||||
fn edit_key(bundle: &mut Bundle, key: String, locale: LanguageIdentifier, editor: &str) {
|
||||
@ -62,28 +61,26 @@ fn edit_key(bundle: &mut Bundle, key: String, locale: LanguageIdentifier, editor
|
||||
#[derive(Clone, Debug, Default)]
|
||||
struct Report {
|
||||
keys: Vec<String>,
|
||||
source_deleted: Vec<String>,
|
||||
// source_deleted: Vec<String>,
|
||||
out_of_date: Vec<String>,
|
||||
}
|
||||
|
||||
impl fmt::Display for Report {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Out of date messages\n")?;
|
||||
writeln!(f, "{} messages in bundle", self.keys.len())?;
|
||||
writeln!(f, "Out of date messages")?;
|
||||
for key in self.out_of_date.iter() {
|
||||
write!(f, "\t{}\n", key)?;
|
||||
writeln!(f, "\t{}", key)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
fn generate_report(
|
||||
bundle: &Bundle,
|
||||
base_locale: &LanguageIdentifier,
|
||||
locales: Vec<LanguageIdentifier>,
|
||||
) -> Report {
|
||||
fn generate_report(bundle: &Bundle, base_locale: &LanguageIdentifier) -> Report {
|
||||
let mut report: Report = Default::default();
|
||||
for (key, message) in bundle.message_iter() {
|
||||
if message.variants_out_of_date(base_locale).len() > 0 {
|
||||
report.keys.push(key.to_owned());
|
||||
if !message.variants_out_of_date(base_locale).is_empty() {
|
||||
report.out_of_date.push(key.to_owned())
|
||||
}
|
||||
}
|
||||
@ -104,9 +101,11 @@ fn main() {
|
||||
let mut bundle = Bundle::load_from_disk(PathBuf::from(&config.db_path));
|
||||
|
||||
match &cli.command {
|
||||
Some(Commands::EditKey { name, locale }) => {
|
||||
let identifier = locale.parse::<LanguageIdentifier>().unwrap();
|
||||
edit_key(&mut bundle, name.to_owned(), identifier, &editor)
|
||||
Some(Commands::EditKey { key, locale }) => {
|
||||
let identifier = locale.as_ref()
|
||||
.map(|l| l.parse::<LanguageIdentifier>().unwrap())
|
||||
.unwrap_or(config.base_locale);
|
||||
edit_key(&mut bundle, key.to_owned(), identifier, &editor)
|
||||
}
|
||||
Some(Commands::ListKeys) => {
|
||||
for (key, _) in bundle.message_iter() {
|
||||
@ -117,22 +116,26 @@ fn main() {
|
||||
import_file(&mut bundle, &PathBuf::from(file)).unwrap();
|
||||
bundle.save();
|
||||
}
|
||||
Some(Commands::Export { format, locale }) => {
|
||||
Some(Commands::Export {
|
||||
format,
|
||||
file,
|
||||
locale,
|
||||
}) => {
|
||||
let locale = locale
|
||||
.as_ref()
|
||||
.map(|l| l.clone().parse::<LanguageIdentifier>().unwrap())
|
||||
.unwrap_or(langid!("en"));
|
||||
|
||||
match format.as_ref() {
|
||||
"js" => js::export_file(&bundle, locale, &PathBuf::from("output.json")).unwrap(),
|
||||
"js" => js::export_file(&bundle, locale, &PathBuf::from(file)).unwrap(),
|
||||
"xliff" => {
|
||||
xliff::export_file(&bundle, locale, &PathBuf::from("output.xliff")).unwrap()
|
||||
xliff::export_file(&bundle, locale, &PathBuf::from(file)).unwrap()
|
||||
}
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
Some(Commands::Report) => {
|
||||
let report = generate_report(&bundle, &config.base_locale, config.locales);
|
||||
let report = generate_report(&bundle, &config.base_locale);
|
||||
println!("{}", report);
|
||||
}
|
||||
None => {}
|
||||
|
@ -47,7 +47,7 @@ impl Bundle {
|
||||
|
||||
fn save_file(path: &PathBuf, s: &[u8]) {
|
||||
let mut f = File::create(path).unwrap();
|
||||
f.write(s).unwrap();
|
||||
let _ = f.write(s).unwrap();
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
|
@ -1,11 +1,10 @@
|
||||
use std::{io::{BufReader, Read, Write}, path::Path, process::Command};
|
||||
use std::{io::Write, process::Command};
|
||||
|
||||
use icu_locid::{langid, LanguageIdentifier};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{read_fh, Message};
|
||||
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
struct EditorMessage {
|
||||
description: String,
|
||||
@ -13,19 +12,7 @@ struct EditorMessage {
|
||||
content: String,
|
||||
}
|
||||
|
||||
/*
|
||||
impl EditorMessage {
|
||||
fn from_variant(description: String, variant: &Variant) -> Self {
|
||||
Self {
|
||||
description,
|
||||
content: variant.content().to_string()
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
pub struct Editor {
|
||||
}
|
||||
pub struct Editor {}
|
||||
|
||||
impl Editor {
|
||||
pub fn edit(msg: &mut Message, locale: LanguageIdentifier, editor: &str) {
|
||||
@ -47,10 +34,10 @@ impl Editor {
|
||||
let file = file.reopen().unwrap();
|
||||
let content = read_fh(&file).unwrap();
|
||||
|
||||
let new_variant: EditorMessage = toml::from_str(&String::from_utf8(content).unwrap()).unwrap();
|
||||
let new_variant: EditorMessage =
|
||||
toml::from_str(&String::from_utf8(content).unwrap()).unwrap();
|
||||
|
||||
variant.set_content(new_variant.content);
|
||||
msg.set_description(new_variant.description);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ pub fn export_fh(bundle: &Bundle, locale: LanguageIdentifier, fh: &mut File) ->
|
||||
}).collect::<Vec<(String, String)>>();
|
||||
|
||||
let messages: BTreeMap<String, String> = messages.into_iter().collect();
|
||||
fh.write(serde_json::to_string_pretty(&messages).unwrap().as_bytes()).unwrap();
|
||||
let _ = fh.write(serde_json::to_string_pretty(&messages).unwrap().as_bytes()).unwrap();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -1,25 +1,14 @@
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
fs::File,
|
||||
io::{self, BufReader, Read, Write},
|
||||
io::{BufReader, Read, Write},
|
||||
path::Path,
|
||||
};
|
||||
|
||||
use chrono::{DateTime, Utc};
|
||||
use icu_locid::{langid, LanguageIdentifier};
|
||||
use xml::{attribute::OwnedAttribute, reader, writer, EmitterConfig, EventReader, EventWriter};
|
||||
|
||||
use crate::{Bundle, Message, ReadError, WriteError};
|
||||
|
||||
struct PartialMessage {
|
||||
variants: HashMap<LanguageIdentifier, PartialVariant>,
|
||||
}
|
||||
|
||||
struct PartialVariant {
|
||||
content: Option<String>,
|
||||
modified: Option<DateTime<Utc>>,
|
||||
}
|
||||
|
||||
pub fn export_file(
|
||||
bundle: &Bundle,
|
||||
locale: LanguageIdentifier,
|
||||
@ -133,12 +122,12 @@ fn write_message<T>(
|
||||
.into(),
|
||||
writer::XmlEvent::start_element("notes").into(),
|
||||
writer::XmlEvent::start_element("note").into(),
|
||||
writer::XmlEvent::characters(message.description()).into(),
|
||||
writer::XmlEvent::characters(message.description()),
|
||||
writer::XmlEvent::end_element().into(),
|
||||
writer::XmlEvent::end_element().into(),
|
||||
writer::XmlEvent::start_element("segment").into(),
|
||||
writer::XmlEvent::start_element("source").into(),
|
||||
writer::XmlEvent::characters(message.variant(locale).unwrap().content()).into(),
|
||||
writer::XmlEvent::characters(message.variant(locale).unwrap().content()),
|
||||
writer::XmlEvent::end_element().into(),
|
||||
writer::XmlEvent::end_element().into(),
|
||||
writer::XmlEvent::end_element().into(),
|
||||
|
Loading…
Reference in New Issue
Block a user