diff --git a/.vscode/settings.json b/.vscode/settings.json index b36583f..0eca799 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,6 +1,7 @@ { "rust-analyzer.linkedProjects": [ "./dyesub-tool/Cargo.toml", + "./dyesub-cli/Cargo.toml", "./dyesub/Cargo.toml", "./svg-units/Cargo.toml", ] diff --git a/Cargo.lock b/Cargo.lock index b8c9100..518257e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,6 +37,55 @@ dependencies = [ "memchr", ] +[[package]] +name = "anstream" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ca84f3628370c59db74ee214b3263d58f9aadd9b4fe7e711fd87dc452b7f163" +dependencies = [ + "anstyle", + "anstyle-parse", + "anstyle-query", + "anstyle-wincon", + "colorchoice", + "is-terminal", + "utf8parse", +] + +[[package]] +name = "anstyle" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a30da5c5f2d5e72842e00bcb57657162cdabef0931f40e2deb9b4140440cecd" + +[[package]] +name = "anstyle-parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "938874ff5980b03a87c5524b3ae5b59cf99b1d6bc836848df7bc5ada9643c333" +dependencies = [ + "utf8parse", +] + +[[package]] +name = "anstyle-query" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca11d4be1bab0c8bc8734a9aa7bf4ee8316d462a08c6ac5052f888fef5b494b" +dependencies = [ + "windows-sys", +] + +[[package]] +name = "anstyle-wincon" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c677ab05e09154296dd37acecd46420c17b9713e8366facafa8fc0885167cf4c" +dependencies = [ + "anstyle", + "windows-sys", +] + [[package]] name = "anyhow" version = "1.0.75" @@ -176,6 +225,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "bitflags" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" + [[package]] name = "block-buffer" version = "0.10.4" @@ -245,6 +300,45 @@ dependencies = [ "half", ] +[[package]] +name = "clap" +version = "4.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03aef18ddf7d879c15ce20f04826ef8418101c7e528014c3eeea13321047dca3" +dependencies = [ + "clap_builder", +] + +[[package]] +name = "clap_builder" +version = "4.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8ce6fffb678c9b80a70b6b6de0aad31df727623a70fd9a842c30cd573e2fa98" +dependencies = [ + "anstream", + "anstyle", + "clap_lex", + "strsim", +] + +[[package]] +name = "clap_derive" +version = "4.3.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "54a9bb5758fc5dfe728d1019941681eccaf0cf8a4189b692a0ee2f2ecf90a050" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 2.0.28", +] + +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + [[package]] name = "class_list" version = "0.1.1" @@ -271,6 +365,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "186dce98367766de751c42c4f03970fc60fc012296e706ccbb9d5df9b6c1e271" +[[package]] +name = "colorchoice" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" + [[package]] name = "config" version = "0.13.3" @@ -411,6 +511,15 @@ dependencies = [ "svg-units", ] +[[package]] +name = "dyesub-cli" +version = "0.1.0" +dependencies = [ + "clap", + "clap_derive", + "dyesub", +] + [[package]] name = "dyesub-tool" version = "0.1.0" @@ -475,6 +584,27 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "errno" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b30f669a7961ef1631673d2766cc92f52d64f7ef354d4fe0ddfd30ed52f0f4f" +dependencies = [ + "errno-dragonfly", + "libc", + "windows-sys", +] + +[[package]] +name = "errno-dragonfly" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +dependencies = [ + "cc", + "libc", +] + [[package]] name = "fnv" version = "1.0.7" @@ -687,6 +817,12 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +[[package]] +name = "hermit-abi" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" + [[package]] name = "html-escape" version = "0.2.13" @@ -811,6 +947,17 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28b29a3cd74f0f4598934efe3aeba42bae0eb4680554128851ebbecb02af14e6" +[[package]] +name = "is-terminal" +version = "0.4.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb0889898416213fab133e1d33a0e5858a48177452750691bde3666d0fdbaf8b" +dependencies = [ + "hermit-abi", + "rustix", + "windows-sys", +] + [[package]] name = "itertools" version = "0.10.5" @@ -1022,6 +1169,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.4.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503" + [[package]] name = "lock_api" version = "0.4.10" @@ -1425,7 +1578,7 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] @@ -1504,7 +1657,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "88073939a61e5b7680558e6be56b419e208420c2adb92be54921fa6b72283f1a" dependencies = [ "base64 0.13.1", - "bitflags", + "bitflags 1.3.2", "serde", ] @@ -1553,6 +1706,19 @@ dependencies = [ "semver", ] +[[package]] +name = "rustix" +version = "0.38.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ed4fa021d81c8392ce04db050a3da9a60299050b7ae1cf482d862b54a7218f" +dependencies = [ + "bitflags 2.4.0", + "errno", + "libc", + "linux-raw-sys", + "windows-sys", +] + [[package]] name = "rustversion" version = "1.0.14" @@ -1768,6 +1934,12 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "strum" version = "0.25.0" @@ -2031,6 +2203,12 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5190c9442dcdaf0ddd50f37420417d219ae5261bbf5db120d0f9bab996c9cba1" +[[package]] +name = "utf8parse" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" + [[package]] name = "uuid" version = "1.4.1" diff --git a/Cargo.toml b/Cargo.toml index 28f5169..35797e0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,3 +1,3 @@ [workspace] -members = ["dyesub-tool", "dyesub", "svg-units"] +members = ["dyesub-tool", "dyesub-cli", "dyesub", "svg-units"] resolver = "2" \ No newline at end of file diff --git a/dyesub-cli/.gitignore b/dyesub-cli/.gitignore new file mode 100644 index 0000000..551c6b3 --- /dev/null +++ b/dyesub-cli/.gitignore @@ -0,0 +1,2 @@ +*.json +*.svg \ No newline at end of file diff --git a/dyesub-cli/Cargo.toml b/dyesub-cli/Cargo.toml new file mode 100644 index 0000000..c32d273 --- /dev/null +++ b/dyesub-cli/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "dyesub-cli" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = "4.3.23" +clap_derive = "4.3.12" +dyesub = { path = "../dyesub" } diff --git a/dyesub-cli/src/main.rs b/dyesub-cli/src/main.rs new file mode 100644 index 0000000..12e3dc7 --- /dev/null +++ b/dyesub-cli/src/main.rs @@ -0,0 +1,31 @@ +#![feature(path_file_prefix)] + +use std::path::PathBuf; + +use clap::Parser; +use clap_derive::Parser; +use dyesub::Result; + +#[derive(Parser, Debug)] +#[command(author, version, about, long_about = None)] +struct Args { + /// Input KLE JSON path + input: PathBuf, + /// Output SVG path + #[arg(short, long)] + output: Option, +} + +fn main() -> Result<()> { + let args = Args::parse(); + let output = args.output.unwrap_or_else(|| { + let mut path = args.input.clone(); + path.set_extension("svg"); + path + }); + dyesub::render_file( + &args.input, + &output, + )?; + Ok(()) +} diff --git a/flake.nix b/flake.nix index c76bdcd..ecc8ed1 100644 --- a/flake.nix +++ b/flake.nix @@ -46,16 +46,26 @@ Updating `cargoHash`: }) bacon ]; - inputsFrom = with self.packages.${system}; [ dyesub-tool ]; + inputsFrom = with self.packages.${system}; [ dyesub-tool dyesub-cli ]; }; packages.${system} = { - default = self.packages.${system}.dyesub-tool; + # TODO: use nightly + default = self.packages.${system}.dyesub-cli; + dyesub-cli = pkgs.rustPlatform.buildRustPackage (rustSettings // { + pname = "dyesub-cli"; + version = "0.1.0"; + buildAndTestSubdir = "dyesub-cli"; + cargoHash = "sha256-S4GvLg/B/FxjNyrQyBg25OMTgJVVBwPO+Dy/EFM4WoQ="; + meta = meta // { + description = "A tool for generating dye sublimation transfer sheet SVGs for Japanese thumb shift 拇指シフト keycaps."; + }; + }); dyesub-tool = pkgs.rustPlatform.buildRustPackage (rustSettings // { pname = "dyesub-tool"; version = "0.1.0"; buildAndTestSubdir = "dyesub-tool"; buildInputs = with pkgs; [ trunk ]; - cargoHash = "sha256-52zTjWRXq058BhuRj2A7mvWzC88UCEolodnBcfa3Ol8="; + cargoHash = "sha256-KSBTEBHuWaenIVaKUMDRFToYxcTA/TFwsIG10WNP47g="; meta = meta // { description = "A tool for generating dye sublimation transfer sheet SVGs for Japanese thumb shift 拇指シフト keycaps."; };