From a7b16850f2437b015bcec8919586c4d4b070a35e Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Mon, 17 Jan 2022 23:52:15 -0500 Subject: use structopt --- Cargo.lock | 161 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 2 + src/main.rs | 21 +++++--- 3 files changed, 176 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index edcef5f..e1351da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "ansi_term" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" +dependencies = [ + "winapi 0.3.9", +] + [[package]] name = "anyhow" version = "1.0.52" @@ -148,6 +157,17 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "065374052e7df7ee4047b1160cca5e1467a12351a40b3da123c870ba0b8eda2a" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi 0.3.9", +] + [[package]] name = "autocfg" version = "1.0.1" @@ -249,6 +269,22 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "clap" +version = "2.34.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" +dependencies = [ + "ansi_term", + "atty", + "bitflags", + "strsim", + "term_size", + "textwrap", + "unicode-width", + "vec_map", +] + [[package]] name = "concurrent-queue" version = "1.2.2" @@ -475,6 +511,15 @@ dependencies = [ "web-sys", ] +[[package]] +name = "heck" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" +dependencies = [ + "unicode-segmentation", +] + [[package]] name = "hermit-abi" version = "0.1.19" @@ -754,11 +799,13 @@ dependencies = [ "nix", "notify", "once_cell", + "paw", "pest", "pest_derive", "pty-process", "serde", "signal-hook-async-std", + "structopt", "terminal_size", "textmode", "time", @@ -856,6 +903,33 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "427c3892f9e783d91cc128285287e70a59e206ca452770ece88a76f7a3eddd72" +[[package]] +name = "paw" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09c0fc9b564dbc3dc2ed7c92c0c144f4de340aa94514ce2b446065417c4084e9" +dependencies = [ + "paw-attributes", + "paw-raw", +] + +[[package]] +name = "paw-attributes" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f35583365be5d148e959284f42526841917b7bfa09e2d1a7ad5dde2cf0eaa39" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "paw-raw" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f0b59668fe80c5afe998f0c0bf93322bf2cd66cafeeb80581f291716f3467f2" + [[package]] name = "percent-encoding" version = "2.1.0" @@ -936,6 +1010,30 @@ dependencies = [ "winapi 0.3.9", ] +[[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.36" @@ -1062,6 +1160,37 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "strsim" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" + +[[package]] +name = "structopt" +version = "0.3.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "40b9788f4202aa75c240ecc9c15c65185e6a39ccdeb0fd5d008b98825464c87c" +dependencies = [ + "clap", + "lazy_static", + "paw", + "structopt-derive", +] + +[[package]] +name = "structopt-derive" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "syn" version = "1.0.84" @@ -1073,6 +1202,16 @@ dependencies = [ "unicode-xid", ] +[[package]] +name = "term_size" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e4129646ca0ed8f45d09b929036bafad5377103edd06e50bf574b353d2b08d9" +dependencies = [ + "libc", + "winapi 0.3.9", +] + [[package]] name = "terminal_size" version = "0.1.17" @@ -1097,6 +1236,16 @@ dependencies = [ "vt100", ] +[[package]] +name = "textwrap" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +dependencies = [ + "term_size", + "unicode-width", +] + [[package]] name = "time" version = "0.3.5" @@ -1149,6 +1298,12 @@ dependencies = [ "tinyvec", ] +[[package]] +name = "unicode-segmentation" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8895849a949e7845e06bd6dc1aa51731a103c42707010a5b591c0038fb73385b" + [[package]] name = "unicode-width" version = "0.1.9" @@ -1205,6 +1360,12 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "vec_map" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 5bf19fb..99f0202 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,11 +19,13 @@ libc = "0.2.112" nix = "0.23.1" notify = "4.0.17" once_cell = "1.9.0" +paw = "1.0.0" pest = "2.1.3" pest_derive = "2.1.0" pty-process = { version = "0.2.0", features = ["async"] } serde = { version = "1.0.133", features = ["derive"] } signal-hook-async-std = "0.2.1" +structopt = { version = "0.3.25", features = ["paw", "wrap_help"] } terminal_size = "0.1.17" textmode = { version = "0.3.0", features = ["async"] } time = { version = "0.3.5", features = ["formatting", "parsing"] } diff --git a/src/main.rs b/src/main.rs index 48d2b2b..3c57bf8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,21 +26,26 @@ mod shell; use prelude::*; +#[derive(structopt::StructOpt)] +#[structopt(about = "NoteBook SHell")] +struct Opt { + #[structopt(short = "c")] + command: Option, +} + async fn async_main( + opt: Opt, shell_write: Option<&async_std::fs::File>, ) -> anyhow::Result { - if std::env::args().nth(1).as_deref() == Some("-c") { - return runner::run( - std::env::args().nth(2).as_deref().unwrap(), - shell_write, - ) - .await; + if let Some(command) = opt.command { + return runner::run(&command, shell_write).await; } shell::main().await } -fn main() { +#[paw::main] +fn main(opt: Opt) { // need to do this here because the async-std executor allocates some fds, // and so in the case where we aren't being called from the main shell and // fd 3 wasn't preallocated in advance, we need to be able to tell that @@ -58,7 +63,7 @@ fn main() { None }; - match async_std::task::block_on(async_main(shell_write.as_ref())) { + match async_std::task::block_on(async_main(opt, shell_write.as_ref())) { Ok(code) => { std::process::exit(code); } -- cgit v1.2.3-54-g00ecf