Skip to content

Commit 95cc53a

Browse files
committed
rework commit chain 3
1 parent 1e33c4e commit 95cc53a

7 files changed

Lines changed: 88 additions & 44 deletions

File tree

Cargo.lock

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,4 @@ png = "0.18.0"
2121
rand = "0.9.2"
2222
thiserror = "2.0.17"
2323
tracing = "0.1.44"
24-
tracing-subscriber = "0.3.22"
24+
tracing-subscriber = { version = "0.3.22", features = ["env-filter"]}

src/config/gradient.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ impl GradientArgs {
2626
))
2727
};
2828

29-
let end = match parse::color(table.get::<Value>("last")?) {
29+
let last = match parse::color(table.get::<Value>("last")?) {
3030
Ok(color) => color,
3131
Err(e) => return Err(mlua::Error::RuntimeError(
32-
format!("While processing 'gradient(end)': {e}")
32+
format!("While processing 'gradient(last)': {e}")
3333
))
3434
};
3535

@@ -40,7 +40,7 @@ impl GradientArgs {
4040
))
4141
};
4242

43-
Ok(Self { start, last: end, at })
43+
Ok(Self { start, last, at })
4444
}
4545
_ => Err(mlua::Error::RuntimeError(format!("While calling provided function 'gradient':\n Expected: GradientArgs\n Got: {}", input.type_name())))
4646
}

src/config/output.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ fn parse_table(table: Table, loc: &Location) -> Result<Output, AppError> {
3232
opt_simple!(width, uint_necessary, table, loc);
3333
opt_simple!(height, uint_necessary, table, loc);
3434

35-
// handle offset default
36-
let offset = offset.unwrap_or_else(|| offset_default());
35+
// handle defaults
36+
let offset = offset.unwrap_or_else(offset_default);
3737

3838
Ok(Output {
3939
directory,

src/main.rs

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,58 @@ mod cli;
44
mod config;
55
mod error;
66
mod image;
7+
mod result;
78
mod runtime;
89
mod user_data;
9-
mod result;
1010
mod util;
1111

12-
use error::AppError;
13-
use cli::Args;
1412
use clap::Parser;
13+
use cli::Args;
1514
use config::Config;
16-
use runtime::Runtime;
17-
use result::*;
18-
15+
use error::AppError;
1916
use image::Image;
20-
17+
use result::*;
18+
use runtime::Runtime;
2119
use std::{env::set_current_dir, process};
20+
use tracing_subscriber::EnvFilter;
21+
22+
fn mainmain() -> Result<(), AppError> {
23+
let trace_format = tracing_subscriber::fmt::format()
24+
.without_time()
25+
.pretty();
26+
let trace_filter = EnvFilter::from_default_env();
27+
tracing_subscriber::fmt()
28+
.event_format(trace_format)
29+
.with_env_filter(trace_filter)
30+
.init();
2231

23-
fn main() {
2432
let args = Args::parse();
2533

26-
match &args.command {
27-
Some(c) => {
28-
question_mark(c.run(&args));
29-
process::exit(0)
30-
}
31-
None => {}
32-
}
34+
if let Some(c) = &args.command { return c.run(&args) }
3335

3436
// TODO make dir if nonexistent? populate with default config?
3537
if let Err(e) = set_current_dir(config::config_dir()) {
36-
println!("Failed to open configuration directory {}:\n{}", config::config_dir(), e);
37-
process::exit(1)
38+
return Err(AppError::Runtime(
39+
format!("Failed to open configuration directory {}:\n{}", config::config_dir(), e)
40+
))
3841
}
3942

40-
let config = question_mark(Config::parse());
41-
let runtime = question_mark(Runtime::from_config(config));
43+
let runtime = Runtime::from_config( Config::parse()? )?;
44+
let path = runtime.save_path(&args.path);
4245

43-
let result = ResultAnchors::new(&runtime);
44-
let result = question_mark(result.to_tiles(&runtime));
45-
let result = result.to_infos();
46-
let result = question_mark(result.to_colors(&runtime));
47-
let result = result.finalize();
46+
let result = ResultAnchors::new(&runtime)
47+
.to_tiles(&runtime)?
48+
.to_infos()
49+
.to_colors(&runtime)?
50+
.finalize();
4851

49-
let path = runtime.save_path(&args.path);
50-
question_mark(result.save(&path));
52+
result.save(&path)
5153
}
5254

53-
fn question_mark<T>(input: Result<T, AppError>) -> T {
54-
match input {
55-
Ok(result) => result,
56-
Err(e) => {
57-
println!("{}", e);
58-
process::exit(1)
59-
}
60-
}
61-
}
55+
fn main() {
56+
if let Err(err) = mainmain() {
57+
println!("{err}");
6258

59+
process::exit(1)
60+
}
61+
}

src/runtime/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,8 @@ impl Runtime {
7777
}
7878
};
7979

80-
let recipe = match tileset.recipes.get(&recipe_name) {
81-
Some(recipe) => recipe,
82-
None => return Err(AppError::Runtime(
80+
let Some(recipe) = tileset.recipes.get(&recipe_name) else {
81+
return Err(AppError::Runtime(
8382
format!("No recipe found with name: {recipe_name}")
8483
))
8584
};

src/util.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub mod tests {
2+
#![allow(dead_code)]
23
use mlua::{Lua, Value};
34

45
pub struct TestVal {
@@ -13,6 +14,12 @@ pub mod tests {
1314

1415
Self { lua, val }
1516
}
17+
18+
pub fn new_with_lua(lua: Lua, input: &'static str) -> Self {
19+
let val = lua.load(input).eval::<Value>().unwrap();
20+
21+
Self { lua, val }
22+
}
1623
}
1724
}
1825

0 commit comments

Comments
 (0)