Skip to content

Commit 2e7a85f

Browse files
Merge pull request #17 from ComputerDruid/push-ypttykpqlvmy
Add save subcommand
2 parents ab88f59 + dd169b3 commit 2e7a85f

6 files changed

Lines changed: 430 additions & 5 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Unreleased
22

3+
### Added
4+
- New subcommand: `save`, which saves blueprints as a .json file, or as a directory of json files for blueprint books
5+
36
### Changed
47
- `upgrade-quality` works on combinators
58
- `upgrade-quality` now errors when encountering something that looks like a quality that it doesn't know if it should upgrade.

Cargo.lock

Lines changed: 96 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ base64 = "0.22.1"
1010
clap = { version = "4.5.42", features = ["derive"] }
1111
crossterm = { version = "0.29.0", features = ["osc52"] }
1212
flate2 = { version = "1.1.2", default-features = false, features = ["zlib-rs"] }
13+
sanitize-filename = "0.6.0"
1314
serde = { version = "1.0.219", features = ["derive"] }
1415
serde_json = "1.0.142"
1516
zlib-rs = "0.5.1"
@@ -23,3 +24,4 @@ lto = "thin"
2324
jaq-core = "2.2.1"
2425
jaq-json = { version = "1.1.3", features = ["serde_json"] }
2526
jaq-std = "2.1.2"
27+
tempfile = "3.21.0"

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Commands:
1010
unwrap Unwraps a blueprint string to reveal the json representation
1111
wrap Wraps json from stdin into a blueprint string
1212
upgrade-quality Upgrades the quality of recipies/filters/conditions without upgrading entities/modules
13+
save Saves blueprint as a .json file, or as a directory of json files if it's a blueprint book
1314
help Print this message or the help of the given subcommand(s)
1415
1516
Options:

src/main.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
mod blueprint;
22
mod json_walk;
3+
mod save;
34

4-
use std::{
5-
fmt::Write as _,
6-
io::{Read, stderr, stdin},
7-
};
5+
use std::fmt::Write;
6+
use std::io::{Read, stderr, stdin};
7+
use std::str::FromStr;
88

99
use blueprint::{blueprint_to_json, json_to_blueprint};
1010
use clap::{Parser, Subcommand};
@@ -43,6 +43,8 @@ enum Commands {
4343
to_clipboard: bool,
4444
blueprint_string: Option<String>,
4545
},
46+
/// Saves blueprint as a .json file, or as a directory of json files if it's a blueprint book.
47+
Save { blueprint_string: Option<String> },
4648
}
4749

4850
mod terminal;
@@ -131,6 +133,13 @@ impl Commands {
131133
println!("{bp}");
132134
}
133135
}
136+
Commands::Save { blueprint_string } => {
137+
let blueprint_string = blueprint_string.unwrap_or_else(terminal::prompt_blueprint);
138+
let json = blueprint_to_json(&blueprint_string);
139+
let json = serde_json::Value::from_str(&json).expect("should contain valid json");
140+
141+
save::save(json, None);
142+
}
134143
}
135144
}
136145
}

0 commit comments

Comments
 (0)