mirror of
https://git.2ki.xyz/spiders/kijetesantakaluotokieni.git
synced 2024-11-22 09:50:25 +01:00
added support for english error mode
This commit is contained in:
parent
1fb2ed8cab
commit
f6631b141e
2 changed files with 72 additions and 34 deletions
|
@ -52,7 +52,7 @@ impl CritterConfig {
|
||||||
object: &Option<String>,
|
object: &Option<String>,
|
||||||
format: &Option<String>,
|
format: &Option<String>,
|
||||||
name: &Option<String>,
|
name: &Option<String>,
|
||||||
) -> Result<CritterConfig, String> {
|
) -> Result<CritterConfig, (String, String)> {
|
||||||
let template: CritterTemplate;
|
let template: CritterTemplate;
|
||||||
if let Some(name) = name {
|
if let Some(name) = name {
|
||||||
template = match name.as_str() {
|
template = match name.as_str() {
|
||||||
|
@ -415,7 +415,7 @@ $8 (III|\|| $9$0"
|
||||||
.replace("$0", &self.object);
|
.replace("$0", &self.object);
|
||||||
}
|
}
|
||||||
// attempts to interpret file as a path, and if this fails, tries appending it to every location in the kijepath environment variable.
|
// attempts to interpret file as a path, and if this fails, tries appending it to every location in the kijepath environment variable.
|
||||||
fn template_from_file(name: &str) -> Result<CritterTemplate, String> {
|
fn template_from_file(name: &str) -> Result<CritterTemplate, (String, String)> {
|
||||||
let mut file = fs::read_to_string(name);
|
let mut file = fs::read_to_string(name);
|
||||||
let paths = path();
|
let paths = path();
|
||||||
if file.is_err() && !paths.is_empty() {
|
if file.is_err() && !paths.is_empty() {
|
||||||
|
@ -429,42 +429,54 @@ $8 (III|\|| $9$0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let file = file.map_err(|_| format!("mi ken ala lukin e nimi kije {}.\n - sina wile lukin e kije ale la o `kijetesantakaluotokieni --seme`\n - sina ken kepeken nimi suli, sama ni: /home/mi/kije\n - nimi poki li lon nimi $NASINKIJE la ilo kijetesantakaluotokieni li\n alasa lon poki ni. o kipisi e nimi poki kepeken sitelen \":\".\n\ncouldn't find/read kijefile {}. check available critters with -l or --seme, try again with a full file path, or add colon-separated directories to $NASINKIJE", name, name))?;
|
let file = file.map_err(|_| (
|
||||||
|
format!("mi ken ala lukin e nimi kije {}.\n - sina wile lukin e kije ale la o `kijetesantakaluotokieni --seme`\n - sina ken kepeken nimi suli, sama ni: /home/mi/kije\n - nimi poki li lon nimi $NASINKIJE la ilo kijetesantakaluotokieni li\n alasa lon poki ni. o kipisi e nimi poki kepeken sitelen \":\".", name),
|
||||||
|
format!("couldn't find/read kijefile {}. check available critters with -l or --seme, try again with a full file path, or add colon-separated directories to $NASINKIJE", name)
|
||||||
|
))?;
|
||||||
|
|
||||||
let mut lines = file.lines().skip_while(|l| l.starts_with('#')); // skips comments
|
let mut lines = file.lines().skip_while(|l| l.starts_with('#')); // skips comments
|
||||||
|
|
||||||
let anchor: usize;
|
let anchor: usize;
|
||||||
if let Some(anchor_line) = lines.next() {
|
if let Some(anchor_line) = lines.next() {
|
||||||
anchor = anchor_line.trim().parse().map_err(|_| {
|
anchor = anchor_line.trim().parse().map_err(|_| {
|
||||||
"nanpa li nasa lon lipu kije. o pona e ona.\n\ncouldn't parse anchor as number"
|
(
|
||||||
.to_string()
|
"nanpa li nasa lon lipu kije. o pona e ona.".to_string(),
|
||||||
|
"couldn't parse anchor as number".to_string(),
|
||||||
|
)
|
||||||
})?;
|
})?;
|
||||||
} else {
|
} else {
|
||||||
return Err("ale li weka tan lipu kije. ona li wile e nanpa e sitelen.\n\nkijefile missing content".to_string());
|
return Err((
|
||||||
|
"ale li weka tan lipu kije. ona li wile e nanpa e sitelen.".to_string(),
|
||||||
|
"kijefile missing content".to_string(),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
let default_left_eye = lines
|
let default_left_eye = lines
|
||||||
.next()
|
.next()
|
||||||
.ok_or(
|
.ok_or((
|
||||||
"lukin nanpa wan li lon ala lipu kije\nleft eye missing from kijefile".to_string(),
|
"lukin nanpa wan li lon ala lipu kije".to_string(),
|
||||||
)?
|
"left eye missing from kijefile".to_string(),
|
||||||
|
))?
|
||||||
.to_string();
|
.to_string();
|
||||||
let default_right_eye = lines
|
let default_right_eye = lines
|
||||||
.next()
|
.next()
|
||||||
.ok_or(
|
.ok_or((
|
||||||
"lukin nanpa tu li lon ala lipu kije\nright eye missing from kijefile".to_string(),
|
"lukin nanpa tu li lon ala lipu kije".to_string(),
|
||||||
)?
|
"right eye missing from kijefile".to_string(),
|
||||||
|
))?
|
||||||
.to_string();
|
.to_string();
|
||||||
let default_left_tongue = lines
|
let default_left_tongue = lines
|
||||||
.next()
|
.next()
|
||||||
.ok_or(
|
.ok_or((
|
||||||
"uta nanpa wan li lon ala lipu kije\nleft tongue missing from kijefile".to_string(),
|
"uta nanpa wan li lon ala lipu kije".to_string(),
|
||||||
)?
|
"left tongue missing from kijefile".to_string(),
|
||||||
|
))?
|
||||||
.to_string();
|
.to_string();
|
||||||
let default_right_tongue = lines
|
let default_right_tongue = lines
|
||||||
.next()
|
.next()
|
||||||
.ok_or(
|
.ok_or((
|
||||||
"uta nanpa tu li lon ala lipu kije\nright tongue missing from kijefile".to_string(),
|
"uta nanpa tu li lon ala lipu kije".to_string(),
|
||||||
)?
|
"right tongue missing from kijefile".to_string(),
|
||||||
|
))?
|
||||||
.to_string();
|
.to_string();
|
||||||
let mut critter = String::new();
|
let mut critter = String::new();
|
||||||
lines.for_each(|l| critter.push_str(&format!("{}\n", l).to_string()));
|
lines.for_each(|l| critter.push_str(&format!("{}\n", l).to_string()));
|
||||||
|
@ -487,7 +499,7 @@ fn path() -> Vec<String> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_files() -> Result<Vec<String>, String> {
|
pub fn list_files() -> Result<Vec<String>, (String, String)> {
|
||||||
let mut files = Vec::new();
|
let mut files = Vec::new();
|
||||||
// must be updated alongside the name match statement in CritterConfig::config_from_string
|
// must be updated alongside the name match statement in CritterConfig::config_from_string
|
||||||
for builtin in [
|
for builtin in [
|
||||||
|
@ -515,28 +527,41 @@ pub fn list_files() -> Result<Vec<String>, String> {
|
||||||
match fs::read_dir(&i) {
|
match fs::read_dir(&i) {
|
||||||
Err(e) => match e.kind() {
|
Err(e) => match e.kind() {
|
||||||
io::ErrorKind::PermissionDenied => {
|
io::ErrorKind::PermissionDenied => {
|
||||||
return Err(
|
return Err((
|
||||||
format!("mi ken ala lukin e poki ni: {}\n\npermission denied", i)
|
format!("mi ken ala lukin e poki ni: {}", i),
|
||||||
.to_string(),
|
format!("{}: permission denied", i),
|
||||||
)
|
))
|
||||||
}
|
}
|
||||||
io::ErrorKind::NotFound => {
|
io::ErrorKind::NotFound => {
|
||||||
return Err(format!(
|
return Err((
|
||||||
"poki ni li lon ala: {}\n\ndirectory not found",
|
format!("poki ni li lon ala: {}", i),
|
||||||
i.to_string()
|
format!("{}: directory not found", i),
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
return Err(format!("ijo li pakala lon ni: {}\n\n{:?}", i, e.kind()).to_string())
|
return Err((
|
||||||
|
format!("ijo li pakala lon ni: {}\n{:?}", i, e.kind()),
|
||||||
|
format!("{}: an error occurred: {:?}", i, e.kind()),
|
||||||
|
))
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Ok(entries) => {
|
Ok(entries) => {
|
||||||
for read in entries {
|
for read in entries {
|
||||||
let filename = read
|
let filename = read
|
||||||
.map_err(|e|format!("mi ken ala lukin e lipu lon ni: {}\n\n{}", i, e.to_string()).to_string())?
|
.map_err(|e| {
|
||||||
|
(
|
||||||
|
format!("mi ken ala lukin e lipu lon ni: {}\n{}", i, e.to_string()),
|
||||||
|
format!("can't read file: {}\n{}", i, e.to_string()),
|
||||||
|
)
|
||||||
|
})?
|
||||||
.file_name()
|
.file_name()
|
||||||
.into_string()
|
.into_string()
|
||||||
.map_err(|_|format!("mi ken ala sitelen UTF-8 e nimi lipu lon ni: {}\n\ncould not display file name as utf-8", i).to_string())?;
|
.map_err(|_| {
|
||||||
|
(
|
||||||
|
format!("mi ken ala sitelen UTF-8 e nimi lipu lon ni: {}", i),
|
||||||
|
format!("could not display file name in {} as utf-8", i),
|
||||||
|
)
|
||||||
|
})?;
|
||||||
files.push(filename);
|
files.push(filename);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -23,8 +23,12 @@ fn main() {
|
||||||
let mut text = String::new();
|
let mut text = String::new();
|
||||||
let (critter_config, bubble_config);
|
let (critter_config, bubble_config);
|
||||||
match cli.configs_from_arguments() {
|
match cli.configs_from_arguments() {
|
||||||
Err(s) => {
|
Err((s, e)) => {
|
||||||
|
if cli.inli {
|
||||||
|
println!("error:\n{}", e);
|
||||||
|
} else {
|
||||||
println!("pakala a!\n{}", s);
|
println!("pakala a!\n{}", s);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Ok((c, b)) => {
|
Ok((c, b)) => {
|
||||||
|
@ -33,7 +37,13 @@ fn main() {
|
||||||
}
|
}
|
||||||
if cli.seme {
|
if cli.seme {
|
||||||
match critters::list_files() {
|
match critters::list_files() {
|
||||||
Err(e) => println!("{}", e),
|
Err((s, e)) => {
|
||||||
|
if cli.inli {
|
||||||
|
println!("error: {}", e)
|
||||||
|
} else {
|
||||||
|
println!("pakala a!\n{}", s)
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(files) => {
|
Ok(files) => {
|
||||||
print!("{}", files.join(" "))
|
print!("{}", files.join(" "))
|
||||||
}
|
}
|
||||||
|
@ -115,15 +125,18 @@ struct Args {
|
||||||
#[clap(short = 'z', long)]
|
#[clap(short = 'z', long)]
|
||||||
suwi: bool,
|
suwi: bool,
|
||||||
|
|
||||||
#[clap(short = 'I', long)]
|
#[clap(short = 'P', long)]
|
||||||
pilin: bool,
|
pilin: bool,
|
||||||
|
|
||||||
|
#[clap(short = 'I', long)]
|
||||||
|
inli: bool,
|
||||||
|
|
||||||
// optional text input
|
// optional text input
|
||||||
text: Vec<String>,
|
text: Vec<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Args {
|
impl Args {
|
||||||
fn configs_from_arguments(&self) -> Result<(CritterConfig, BubbleConfig), String> {
|
fn configs_from_arguments(&self) -> Result<(CritterConfig, BubbleConfig), (String, String)> {
|
||||||
let mut eyes = self.lukin.clone();
|
let mut eyes = self.lukin.clone();
|
||||||
let mut tongue = self.uta.clone();
|
let mut tongue = self.uta.clone();
|
||||||
let mut line = self.linja.clone();
|
let mut line = self.linja.clone();
|
||||||
|
|
Loading…
Reference in a new issue