From 5c544de74b64fc08029d09d12ecde894b5e78078 Mon Sep 17 00:00:00 2001 From: edef Date: Tue, 3 May 2022 00:08:20 +0000 Subject: ripple/fossil: use clap This adds clap to all our binaries. Only add currently takes any args, but previously, the others did not reject args as they should. Change-Id: I6257fb3b218c624ee0124f6ed7313a579db88c4c --- ripple/Cargo.lock | 94 ++++++++++++++++++++++++++++++++++++++-- ripple/fossil/Cargo.toml | 1 + ripple/fossil/src/bin/add.rs | 14 ++++-- ripple/fossil/src/bin/extract.rs | 6 +++ ripple/fossil/src/bin/mount.rs | 5 +++ 5 files changed, 114 insertions(+), 6 deletions(-) diff --git a/ripple/Cargo.lock b/ripple/Cargo.lock index b605e1b..760317a 100644 --- a/ripple/Cargo.lock +++ b/ripple/Cargo.lock @@ -145,10 +145,49 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" dependencies = [ "bitflags", - "textwrap", + "textwrap 0.11.0", "unicode-width", ] +[[package]] +name = "clap" +version = "3.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85a35a599b11c089a7f49105658d089b8f2cf0882993c17daf6de15285c2c35d" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "lazy_static", + "strsim", + "termcolor", + "textwrap 0.15.0", +] + +[[package]] +name = "clap_derive" +version = "3.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3aab4734e083b809aaf5794e14e756d1c798d2c69c7f7de7a09a2f5214993c1" +dependencies = [ + "heck 0.4.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "constant_time_eq" version = "0.1.5" @@ -172,7 +211,7 @@ checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" dependencies = [ "atty", "cast", - "clap", + "clap 2.34.0", "criterion-plot", "csv", "itertools", @@ -321,6 +360,7 @@ dependencies = [ "blake3", "byteorder", "bytes", + "clap 3.1.15", "criterion", "env_logger", "fuser", @@ -409,6 +449,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -571,6 +617,12 @@ version = "11.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" + [[package]] name = "page_size" version = "0.4.2" @@ -656,6 +708,30 @@ version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ac74c624d6b2d21f425f752262f42188365d7b8ff1aff74c82e45136510a4857" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + [[package]] name = "proc-macro2" version = "1.0.28" @@ -682,7 +758,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "355f634b43cdd80724ee7848f95770e7e70eefa6dcf14fea676216573b8fd603" dependencies = [ "bytes", - "heck", + "heck 0.3.3", "itertools", "log", "multimap", @@ -931,6 +1007,12 @@ version = "1.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe0f37c9e8f3c5a4a66ad655a93c74daac4ad00c441533bf5c6e7990bb42604e" +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + [[package]] name = "subtle" version = "2.4.1" @@ -992,6 +1074,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" + [[package]] name = "tinytemplate" version = "1.2.1" diff --git a/ripple/fossil/Cargo.toml b/ripple/fossil/Cargo.toml index 4008691..a1f39fb 100644 --- a/ripple/fossil/Cargo.toml +++ b/ripple/fossil/Cargo.toml @@ -19,6 +19,7 @@ env_logger = "0.9.0" lazy_static = "1.4.0" bao = "0.12.0" anyhow = "1.0.53" +clap = { version = "3.1.15", features = ["derive"] } [build-dependencies] prost-build = "0.8.0" diff --git a/ripple/fossil/src/bin/add.rs b/ripple/fossil/src/bin/add.rs index 114f893..7768366 100644 --- a/ripple/fossil/src/bin/add.rs +++ b/ripple/fossil/src/bin/add.rs @@ -2,20 +2,28 @@ // SPDX-License-Identifier: OSL-3.0 use { + clap::StructOpt, fossil::Directory, prost::Message, std::{ - env, io::{self, Write}, - path::Path, + path::{Path, PathBuf}, }, }; +#[derive(clap::Parser)] +struct Args { + #[clap(name = "PATH")] + paths: Vec, +} + fn main() { + let args = Args::parse(); + let store = fossil::Store::open("fossil.db").unwrap(); let mut root = Directory::new(); - for name in env::args().skip(1) { + for name in args.paths { let path = Path::new(&name); let name = path .file_name() diff --git a/ripple/fossil/src/bin/extract.rs b/ripple/fossil/src/bin/extract.rs index b21a063..cb45896 100644 --- a/ripple/fossil/src/bin/extract.rs +++ b/ripple/fossil/src/bin/extract.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: OSL-3.0 use { + clap::StructOpt, fossil::{store, Directory}, prost::Message, std::{ @@ -12,7 +13,12 @@ use { }, }; +#[derive(clap::Parser)] +struct Args {} + fn main() { + let _args = Args::parse(); + let store = fossil::Store::open("fossil.db").unwrap(); let root = { let mut stdin = io::stdin(); diff --git a/ripple/fossil/src/bin/mount.rs b/ripple/fossil/src/bin/mount.rs index 2e6945b..ae26fbb 100644 --- a/ripple/fossil/src/bin/mount.rs +++ b/ripple/fossil/src/bin/mount.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: OSL-3.0 use { + clap::StructOpt, fossil::{store, FileRef}, lazy_static::lazy_static, libc::{c_int, EINVAL, ENOENT, ENOSYS, EROFS}, @@ -71,8 +72,12 @@ fn file_attr(ino: u64, node: &memtree::Node) -> fuser::FileAttr { } } +#[derive(clap::Parser)] +struct Args {} + fn main() { env_logger::init(); + let _args = Args::parse(); let store = fossil::Store::open("fossil.db").unwrap(); let root = memtree::load_root(&store, { -- cgit 1.4.1