From cd089e0650bf87ee326557fcff73ed269da96b7b Mon Sep 17 00:00:00 2001 From: Nathan Essex Date: Fri, 23 Sep 2022 01:35:44 +0900 Subject: [PATCH] Release v0.4.0 (#163) --- Cargo.lock | 222 +++++++++++++++++----------- crates/yaml-split/Cargo.toml | 4 +- crates/yaml-split/src/lib.rs | 20 ++- crates/yaml2json-rs-bin/Cargo.toml | 10 +- crates/yaml2json-rs-bin/src/main.rs | 50 +++---- crates/yaml2json-rs/Cargo.toml | 10 +- crates/yaml2json-rs/src/lib.rs | 6 +- 7 files changed, 189 insertions(+), 133 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cfaf0f8..2040a6e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,20 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" -version = "1.0.43" +version = "1.0.65" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28ae2b3dec75a406790005a200b1bd89785afc02517a00ca99ecfe093ee9e6cf" +checksum = "98161a4e3e2184da77bb14f02184cdd111e83bbbcc9979dfee3c44b9a85f5602" [[package]] name = "atty" @@ -30,57 +21,81 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.0.1" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cdb031dd78e28731d87d56cc8ffef4a8f36ca26c38fe2de700543e627f8a464a" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.2.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "clap" -version = "2.33.3" +version = "3.2.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" +checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750" dependencies = [ - "ansi_term", "atty", "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "once_cell", "strsim", + "termcolor", "textwrap", - "unicode-width", - "vec_map", ] [[package]] -name = "dtoa" -version = "0.4.6" +name = "clap_derive" +version = "3.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "134951f4028bdadb9b84baf4232681efbf277da25144b9b0ad65df75946c422b" +checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" +dependencies = [ + "os_str_bytes", +] [[package]] name = "hashbrown" -version = "0.11.2" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "heck" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.1.17" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] [[package]] name = "indexmap" -version = "1.7.0" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", "hashbrown", @@ -88,57 +103,87 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.6" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc6f3ad7b9d11a0c00842ff8de1b60ee58661048eb8049ed33c73594f359d7e6" +checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754" [[package]] name = "libc" -version = "0.2.80" +version = "0.2.133" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966" + +[[package]] +name = "once_cell" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e82dad04139b71a90c080c8463fe0dc7902db5192d939bd0950f074d014339e1" + +[[package]] +name = "os_str_bytes" +version = "6.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff" + +[[package]] +name = "proc-macro-error" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58d1b70b004888f764dfbf6a26a3b0342a1632d33968e4a179d8011c760614" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] [[package]] -name = "linked-hash-map" -version = "0.5.3" +name = "proc-macro-error-attr" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dd5a6d5999d9907cda8ed67bbd137d3af8085216c2ac62de5be860bd41f304a" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] [[package]] name = "proc-macro2" -version = "1.0.24" +version = "1.0.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" +checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.7" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa563d17ecb180e500da1cfd2b028310ac758de548efdd203e18f283af693f37" +checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179" dependencies = [ "proc-macro2", ] [[package]] name = "ryu" -version = "1.0.5" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e" +checksum = "4501abdff3ae82a1c1b477a17252eb69cee9e66eb915c1abaa4f44d873df9f09" [[package]] name = "serde" -version = "1.0.130" +version = "1.0.144" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913" +checksum = "0f747710de3dcd43b88c9168773254e809d8ddbdf9653b84e2554ab219f17860" [[package]] name = "serde_json" -version = "1.0.67" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7f9e390c27c3c0ce8bc5d725f6e4d30a29d26659494aa4b17535f7522c5c950" +checksum = "e55a28e3aaef9d5ce0506d0a14dbba8054ddc7e499ef522dd8b26859ec9d4a44" dependencies = [ "itoa", "ryu", @@ -147,56 +192,63 @@ dependencies = [ [[package]] name = "serde_yaml" -version = "0.8.20" +version = "0.9.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad104641f3c958dab30eb3010e834c2622d1f3f4c530fef1dee20ad9485f3c09" +checksum = "8613d593412a0deb7bbd8de9d908efff5a0cb9ccd8f62c641e7b2ed2f57291d1" dependencies = [ - "dtoa", "indexmap", + "itoa", + "ryu", "serde", - "yaml-rust", + "unsafe-libyaml", ] [[package]] name = "strsim" -version = "0.8.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "syn" -version = "1.0.48" +version = "1.0.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" +checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] -name = "textwrap" -version = "0.11.0" +name = "termcolor" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" dependencies = [ - "unicode-width", + "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16" + [[package]] name = "thiserror" -version = "1.0.29" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "602eca064b2d83369e2b2f34b09c70b605402801927c65c11071ac911d299b88" +checksum = "c53f98874615aea268107765aa1ed8f6116782501d18e53d08b471733bea6c85" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.29" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad553cc2c78e8de258400763a647e80e6d1b31ee237275d756f6836d204494c" +checksum = "f8b463991b4eab2d801e724172285ec4195c650e8ec79b149e6c2a8e6dd3f783" dependencies = [ "proc-macro2", "quote", @@ -204,22 +256,22 @@ dependencies = [ ] [[package]] -name = "unicode-width" -version = "0.1.8" +name = "unicode-ident" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" +checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd" [[package]] -name = "unicode-xid" -version = "0.2.1" +name = "unsafe-libyaml" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7fe0bb3479651439c9112f72b6c505038574c9fbb575ed1bf3b797fa39dd564" +checksum = "c1e5fa573d8ac5f1a856f8d7be41d390ee973daf97c806b2c1a465e4e1406e68" [[package]] -name = "vec_map" -version = "0.8.2" +name = "version_check" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "winapi" @@ -238,30 +290,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" +name = "winapi-util" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] [[package]] -name = "yaml-rust" -version = "0.4.5" +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "yaml-split" -version = "0.3.3" +version = "0.4.0" dependencies = [ "thiserror", ] [[package]] name = "yaml2json-rs" -version = "0.3.3" +version = "0.4.0" dependencies = [ "serde", "serde_json", @@ -271,7 +323,7 @@ dependencies = [ [[package]] name = "yaml2json-rs-bin" -version = "0.3.3" +version = "0.4.0" dependencies = [ "anyhow", "clap", diff --git a/crates/yaml-split/Cargo.toml b/crates/yaml-split/Cargo.toml index 9652a42..15ddf1b 100644 --- a/crates/yaml-split/Cargo.toml +++ b/crates/yaml-split/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yaml-split" description = "provides an iterator over individual YAML documents in a YAML file or stream" -version = "0.3.3" +version = "0.4.0" authors = ["Nathan Essex "] edition = "2018" license = "Apache-2.0 OR MIT" @@ -12,4 +12,4 @@ keywords = ["yaml"] documentation = "https://docs.rs/yaml-split/" [dependencies] -thiserror = "1.0.29" +thiserror = "1.0.35" diff --git a/crates/yaml-split/src/lib.rs b/crates/yaml-split/src/lib.rs index 67f305f..c081f2a 100644 --- a/crates/yaml-split/src/lib.rs +++ b/crates/yaml-split/src/lib.rs @@ -36,10 +36,12 @@ pub enum YamlSplitError { /// # use std::fs::remove_file; /// use yaml_split::DocumentIterator; /// # use std::io::Write; -/// # -/// # File::create("test.yaml").unwrap(); -/// # let mut file = File::open("test.yaml").unwrap(); -/// # file.write(b"hello: world"); +/// let mut file = File::options() +/// .create(true) +/// .write(true) +/// .open("test.yaml") +/// .unwrap() +/// .write(b"hello: world"); /// /// let read_file = File::open("test.yaml").unwrap(); /// let doc_iter = DocumentIterator::new(read_file); @@ -107,10 +109,12 @@ impl<'a, R: Read + 'a> DocumentIterator { /// # use std::fs::remove_file; /// use yaml_split::DocumentIterator; /// # use std::io::Write; - /// # - /// # File::create("test.yml").unwrap(); - /// # let mut file = File::open("test.yml").unwrap(); - /// # file.write(b"hello: world"); + /// let mut file = File::options() + /// .create(true) + /// .write(true) + /// .open("test.yml") + /// .unwrap() + /// .write(b"hello: world"); /// /// let read_file = File::open("test.yml").unwrap(); /// let doc_iter = DocumentIterator::new(read_file); diff --git a/crates/yaml2json-rs-bin/Cargo.toml b/crates/yaml2json-rs-bin/Cargo.toml index b464668..14c1bfd 100644 --- a/crates/yaml2json-rs-bin/Cargo.toml +++ b/crates/yaml2json-rs-bin/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yaml2json-rs-bin" description = "Command line utility to convert YAML files to JSON." -version = "0.3.3" +version = "0.4.0" authors = ["Nathan Essex "] edition = "2018" license = "Apache-2.0 OR MIT" @@ -17,7 +17,7 @@ name = "yaml2json" path = "src/main.rs" [dependencies] -clap = "2.33.3" -anyhow = "1.0.43" -yaml-split = { path = "../yaml-split", version = "=0.3.3" } -yaml2json-rs = { path = "../yaml2json-rs", version = "=0.3.3" } +clap = { version = "3.2.22", features = ["cargo","derive"] } +anyhow = "1.0.65" +yaml-split = { path = "../yaml-split", version = "=0.4.0" } +yaml2json-rs = { path = "../yaml2json-rs", version = "=0.4.0" } diff --git a/crates/yaml2json-rs-bin/src/main.rs b/crates/yaml2json-rs-bin/src/main.rs index da2e291..e7d6881 100644 --- a/crates/yaml2json-rs-bin/src/main.rs +++ b/crates/yaml2json-rs-bin/src/main.rs @@ -1,20 +1,17 @@ -#[macro_use] -extern crate anyhow; -#[macro_use] -extern crate clap; - use std::fs::File; use std::io::{Read, Stderr, Stdout}; use std::path::Path; use std::str::FromStr; use std::{io, process}; -use clap::{App, Arg}; +use clap::{crate_authors, crate_description, crate_name, crate_version, App, Arg}; -use std::fmt::Display; +use anyhow::bail; +use std::fmt::{Display, Formatter}; use yaml2json_rs::{Style, Yaml2Json}; use yaml_split::{DocumentIterator, YamlSplitError}; +#[derive(Clone, clap::ValueEnum)] enum ErrorStyle { Silent, Stderr, @@ -24,7 +21,7 @@ enum ErrorStyle { impl FromStr for ErrorStyle { type Err = anyhow::Error; - fn from_str(s: &str) -> core::result::Result { + fn from_str(s: &str) -> Result { match s { "silent" => Ok(ErrorStyle::Silent), "stderr" => Ok(ErrorStyle::Stderr), @@ -34,14 +31,17 @@ impl FromStr for ErrorStyle { } } -impl ToString for ErrorStyle { - fn to_string(&self) -> String { - match self { - ErrorStyle::Silent => "silent", - ErrorStyle::Stderr => "stderr", - ErrorStyle::Json => "json", - } - .to_string() +impl Display for ErrorStyle { + fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { + write!( + f, + "{}", + match self { + ErrorStyle::Silent => "silent", + ErrorStyle::Stderr => "stderr", + ErrorStyle::Json => "json", + } + ) } } @@ -123,7 +123,6 @@ fn write(yaml2json: &Yaml2Json, ep: &mut ErrorPrinter, read: impl Read) { } fn main() { - let default_err_style = ErrorStyle::Stderr.to_string(); let usage = r#"./yaml2json file1.yaml file2.yaml cat file1.yaml | ./yaml2json @@ -137,18 +136,15 @@ fn main() { .arg( Arg::with_name("pretty") .takes_value(false) - .short("p") + .short('p') .long("pretty") ) .arg( Arg::with_name("error") .takes_value(true) - .short("e") + .short('e') .long("error") - .default_value(&default_err_style) - .possible_value(&ErrorStyle::Silent.to_string()) - .possible_value(&ErrorStyle::Stderr.to_string()) - .possible_value(&ErrorStyle::Json.to_string()) + .default_value("json") ) .arg( Arg::with_name("file") @@ -159,9 +155,13 @@ fn main() { let fileopt = matches.values_of("file"); let pretty = matches.is_present("pretty"); - let error = matches.value_of("error").unwrap(); + let error: ErrorStyle = matches + .value_of("error") + .unwrap() + .parse() + .expect(r#"invalid error value, expected one of "silent", "stderr" or "json""#); - let mut ep = ErrorPrinter::new(ErrorStyle::from_str(error).unwrap(), pretty); + let mut ep = ErrorPrinter::new(error, pretty); let yaml2json_style = if pretty { Style::PRETTY } else { diff --git a/crates/yaml2json-rs/Cargo.toml b/crates/yaml2json-rs/Cargo.toml index fa23dd2..920da90 100644 --- a/crates/yaml2json-rs/Cargo.toml +++ b/crates/yaml2json-rs/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "yaml2json-rs" description = "Convert YAML documents to JSON" -version = "0.3.3" +version = "0.4.0" authors = ["Nathan Essex "] edition = "2018" license = "Apache-2.0 OR MIT" @@ -12,7 +12,7 @@ keywords = ["yaml", "json"] documentation = "https://docs.rs/yaml2json-rs/" [dependencies] -serde = "1.0" -serde_json = "1.0" -serde_yaml = "0.8" -thiserror = "1.0.29" +serde = "1.0.144" +serde_json = "1.0.85" +serde_yaml = "0.9.13" +thiserror = "1.0.35" diff --git a/crates/yaml2json-rs/src/lib.rs b/crates/yaml2json-rs/src/lib.rs index b18f6f8..8e7adca 100644 --- a/crates/yaml2json-rs/src/lib.rs +++ b/crates/yaml2json-rs/src/lib.rs @@ -12,7 +12,7 @@ pub enum Yaml2JsonError { SerdeJsonError(#[from] serde_json::Error), #[error(transparent)] - IOError(#[from] std::io::Error), + IOError(#[from] io::Error), } /// `Style` defines JSON output formats for `Yaml2Json`. @@ -82,7 +82,7 @@ pub enum Style { /// let input = "hello: world"; /// let mut stdout = io::stdout(); /// -/// y2j.document_to_writer(input, &mut stdout); +/// y2j.document_to_writer(input, &mut stdout).unwrap(); /// /// // {"hello":"world"} /// ``` @@ -137,7 +137,7 @@ impl Yaml2Json { /// let input = "hello: world"; /// let mut stdout = io::stdout(); /// - /// y2j.document_to_writer(input, &mut stdout); + /// y2j.document_to_writer(input, &mut stdout).unwrap(); /// /// // {"hello":"world"} /// ```