From e44363ec40bd97066741e66e7c5d0e592db7a50e Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Mon, 6 Mar 2023 18:00:46 +0000 Subject: [PATCH] Get ready to use cli-clap boilerplate --- .gitignore | 11 +- Cargo.lock | 457 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 22 +-- README.md | 59 ++++--- enquirer.1 | 11 -- src/main.rs | 20 +-- 6 files changed, 514 insertions(+), 66 deletions(-) create mode 100644 Cargo.lock delete mode 100644 enquirer.1 diff --git a/.gitignore b/.gitignore index 088ba6b..eb5a316 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1 @@ -# Generated by Cargo -# will have compiled files and executables -/target/ - -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock - -# These are backup files generated by rustfmt -**/*.rs.bk +target diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..c687f5a --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,457 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "cc" +version = "1.0.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "clap" +version = "4.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d7ae14b20b94cb02149ed21a86c423859cbe18dc7ed69845cace50e52b40a5" +dependencies = [ + "bitflags", + "clap_derive", + "clap_lex", + "is-terminal", + "once_cell", + "strsim", + "termcolor", + "terminal_size", +] + +[[package]] +name = "clap_derive" +version = "4.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44bec8e5c9d09e439c4335b1af0abaab56dcf3b94999a936e1bb47b9134288f0" +dependencies = [ + "heck", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "350b9cf31731f9957399229e9b2adc51eeabdfbe9d71d9a0552275fd12710d09" +dependencies = [ + "os_str_bytes", +] + +[[package]] +name = "console" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d79fbe8970a77e3e34151cc13d3b3e248aa0faaecb9f6091fa07ebefe5ad60" +dependencies = [ + "encode_unicode", + "lazy_static", + "libc", + "unicode-width", + "windows-sys 0.42.0", +] + +[[package]] +name = "dialoguer" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3c796f3b0b408d9fd581611b47fa850821fcb84aa640b83a3c1a5be2d691f2" +dependencies = [ + "console", + "shell-words", + "tempfile", + "zeroize", +] + +[[package]] +name = "encode_unicode" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" + +[[package]] +name = "enquirer" +version = "0.6.1" +dependencies = [ + "clap", + "dialoguer", +] + +[[package]] +name = "errno" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f639046355ee4f37944e44f60642c6f3a7efa3cf6b78c78a0d989a8ce6c396a1" +dependencies = [ + "errno-dragonfly", + "libc", + "winapi", +] + +[[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 = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "hermit-abi" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fed44880c466736ef9a5c5b5facefb5ed0785676d0c02d612db14e54f0d84286" + +[[package]] +name = "instant" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "io-lifetimes" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1abeb7a0dd0f8181267ff8adc397075586500b81b28a73e8a0208b00fc170fb3" +dependencies = [ + "libc", + "windows-sys 0.45.0", +] + +[[package]] +name = "is-terminal" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21b6b32576413a8e69b90e952e4a026476040d81017b80445deda5f2d3921857" +dependencies = [ + "hermit-abi", + "io-lifetimes", + "rustix", + "windows-sys 0.45.0", +] + +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + +[[package]] +name = "libc" +version = "0.2.139" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "201de327520df007757c1f0adce6e827fe8562fbc28bfd9c15571c66ca1f5f79" + +[[package]] +name = "linux-raw-sys" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4" + +[[package]] +name = "once_cell" +version = "1.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" + +[[package]] +name = "os_str_bytes" +version = "6.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b7820b9daea5457c9f21c69448905d723fbd21136ccf521748f23fd49e723ee" + +[[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.51" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d727cae5b39d21da60fa540906919ad737832fe0b1c165da3a34d6548c849d6" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8856d8364d252a14d474036ea1358d63c9e6965c8e5c1885c18f73d70bff9c7b" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "redox_syscall" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +dependencies = [ + "bitflags", +] + +[[package]] +name = "rustix" +version = "0.36.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd5c6ff11fecd55b40746d1995a02f2eb375bf8c00d192d521ee09f42bef37bc" +dependencies = [ + "bitflags", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys", + "windows-sys 0.45.0", +] + +[[package]] +name = "shell-words" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "tempfile" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af18f7ae1acd354b992402e9ec5864359d693cd8a79dcbef59f76891701c1e95" +dependencies = [ + "cfg-if", + "fastrand", + "redox_syscall", + "rustix", + "windows-sys 0.42.0", +] + +[[package]] +name = "termcolor" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be55cf8942feac5c765c2c993422806843c9a9a45d4d5c407ad6dd2ea95eb9b6" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "terminal_size" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c9afddd2cec1c0909f06b00ef33f94ab2cc0578c4a610aa208ddfec8aa2b43a" +dependencies = [ + "rustix", + "windows-sys 0.45.0", +] + +[[package]] +name = "unicode-ident" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" + +[[package]] +name = "unicode-width" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" + +[[package]] +name = "version_check" +version = "0.9.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +dependencies = [ + "winapi", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "windows-sys" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-targets" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" + +[[package]] +name = "zeroize" +version = "1.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c394b5bd0c6f669e7275d9c20aa90ae064cb22e75a1cad54e1b34088034b149f" diff --git a/Cargo.toml b/Cargo.toml index 841c82b..b6315c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,18 +1,22 @@ [package] -name = "enquirer" +name = "enquirer" version = "0.6.1" -authors = ["Pavan Kumar Sunkara "] -edition = "2018" + +authors = ["Pavan Kumar Sunkara "] description = "Command line utility for stylish interactive prompts" -categories = ["command-line-utilities", "development-tools"] -repository = "https://github.com/termapps/enquirer" -readme = "README.md" -license = "MIT" -include = ["src/**/*.rs", "Cargo.toml", "LICENSE", "*.md"] +homepage = "https://github.com/termapps/enquirer" +repository = "https://github.com/termapps/enquirer" + +edition = "2018" +rust-version = "1.67.0" + +categories = ["command-line-utilities"] +license = "MIT" +readme = "README.md" [dependencies] +clap = { version = "~4.1.8", features = ["derive", "wrap_help"] } dialoguer = "0.10.0" -clap = { version = "~3.1.0", features = ["derive", "wrap_help"] } [[bin]] name = "enquirer" diff --git a/README.md b/README.md index f9721d1..50ad800 100644 --- a/README.md +++ b/README.md @@ -15,41 +15,47 @@ (uses dialoguer underneath)

+ ## Getting started -Get started with Enquirer, the most powerful command line utility for creating interactive CLI prompts. +1. [Install](#install) +2. [Usage](#usage) + 1. [Command Line Utility](#command-line-utility) +3. [Prompts](#prompts) + 1. [Confirm Prompt](#confirm-prompt) + 2. [Input Prompt](#input-prompt) + 3. [Secret Prompt](#secret-prompt) + 4. [Select Prompt](#select-prompt) + 5. [Multi Select Prompt](#multi-select-prompt) + 6. [Sort Prompt](#sort-prompt) +4. [Changelog](#changelog) -* [Install](#install) -* [Usage](#usage) -* [Prompts](#prompts) -* [About](#about) ## Install `enquirer` is available on Linux, macOS + ### With [Homebrew](https://brew.sh/) ``` $ brew install termapps/tap/enquirer ``` -This is recommended way for installation on macOS since updating to the new version is easy. - + ### With [cargo](https://crates.io/) ``` $ cargo install enquirer ``` + ### Direct Pre-built binary executables are available at [releases page](https://github.com/termapps/enquirer/releases) for macOS (64bit), Linux (64bit, 32bit). Download and unarchive the binary then put the executable in `$PATH`. -> Check [roadmap](#roadmap) for other ways - ## Usage ### Command Line Utility @@ -95,13 +101,6 @@ SUBCOMMANDS: ## Prompts -* [Confirm Prompt](#confirm-prompt) -* [Input Prompt](#input-prompt) -* [Secret Prompt](#secret-prompt) -* [Select Prompt](#select-prompt) -* [Multi Select Prompt](#multi-select-prompt) -* [Sort Prompt](#sort-prompt) - ### Confirm Prompt Prompt that returns `true` or `false` (as strings) @@ -110,6 +109,7 @@ Prompt that returns `true` or `false` (as strings) Enquirer Confirm Prompt

+ #### Usage ``` @@ -136,6 +136,7 @@ Prompt that takes user input and returns a string Enquirer Input Prompt

+ #### Usage ``` @@ -162,6 +163,7 @@ Prompt that takes user input, hides it from the terminal, and returns a string Enquirer Secret Prompt

+ #### Usage ``` @@ -189,6 +191,7 @@ Prompt that allows the user to select from a list of options Enquirer Select Prompt

+ #### Usage ``` @@ -219,6 +222,7 @@ Prompt that allows the user to select multiple items from a list of options Enquirer Multi Select Prompt

+ #### Usage ``` @@ -251,6 +255,7 @@ Prompt that allows the user to sort items in a list Enquirer Sort Prompt

+ #### Usage ``` @@ -274,9 +279,12 @@ ARGS: ... Items that can be sorted ``` -## About + +## Contributors +Here is a list of [Contributors](http://github.com/termapps/enquirer/contributors) -### Roadmap + +### TODO * [Man page generation](https://github.com/clap-rs/clap/issues/552) * Packaging for other operating systems @@ -284,21 +292,20 @@ ARGS: * [Snippet Prompt](https://github.com/enquirer/enquirer#snippet-prompt) * [Export hooks for Clap](https://github.com/clap-rs/clap/issues/1471) -#### Dialoguer issues - -* Select and Multi-Select prompts cursors are after the items list while waiting for user. Maybe change them to be on prompt line. - -### Changelog +## Changelog Please see [CHANGELOG.md](CHANGELOG.md). -### License + +## License MIT/X11 -### Bug Reports + +## Bug Reports Report [here](http://github.com/termapps/enquirer/issues). -### Creator + +## Creator Pavan Kumar Sunkara (pavan.sss1991@gmail.com) Follow me on [github](https://github.com/users/follow?target=pksunkara), [twitter](http://twitter.com/pksunkara) diff --git a/enquirer.1 b/enquirer.1 deleted file mode 100644 index fef6d81..0000000 --- a/enquirer.1 +++ /dev/null @@ -1,11 +0,0 @@ -.TH ENQUIRER 1 -.SH NAME -enquirer \- Command line utility for stylish interactive prompts -.SH SYNOPSIS -.B enquirer -[\fIFLAGS\fR] -.IR subcommand ... -.SH FLAGS -.TP -.BR \-h ", " \-\-help -Prints help information diff --git a/src/main.rs b/src/main.rs index f116fb0..d8afaf0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,9 +11,9 @@ use dialoguer::console::set_colors_enabled; /// Command line utility for stylish interactive prompts #[derive(Debug, Parser)] #[clap(name = "enquirer", version)] -struct Enquirer { +struct App { #[clap(subcommand)] - cmd: EnquirerSubcommand, + cmd: Subcommands, /// Disable colors in the prompt #[clap(long)] @@ -21,7 +21,7 @@ struct Enquirer { } #[derive(Debug, Parser)] -enum EnquirerSubcommand { +enum Subcommands { Confirm(confirm::Confirm), Input(input::Input), Secret(secret::Secret), @@ -32,16 +32,16 @@ enum EnquirerSubcommand { fn main() { // TODO: Specify height for selection prompts (like fzf) - let program = Enquirer::parse(); + let program = App::parse(); set_colors_enabled(!program.no_color); match program.cmd { - EnquirerSubcommand::Confirm(x) => x.run(), - EnquirerSubcommand::Input(x) => x.run(), - EnquirerSubcommand::Secret(x) => x.run(), - EnquirerSubcommand::MultiSelect(x) => x.run(), - EnquirerSubcommand::Select(x) => x.run(), - EnquirerSubcommand::Sort(x) => x.run(), + Subcommands::Confirm(x) => x.run(), + Subcommands::Input(x) => x.run(), + Subcommands::Secret(x) => x.run(), + Subcommands::MultiSelect(x) => x.run(), + Subcommands::Select(x) => x.run(), + Subcommands::Sort(x) => x.run(), } .unwrap(); }