From 1a54ef291083bba92038df4e595eab0c25223c1b Mon Sep 17 00:00:00 2001 From: Igor Petruk Date: Sun, 8 Jan 2023 17:23:50 +0000 Subject: [PATCH] Migrating back clap from v4 to v3 and removing clap_mangen. clap v4 and clap_mangen are not wrapped for Debian just yet and I have materialized man pages into the source code as a good start. Automatically generated man pages required post-editing anyway, clap_mangen is far from being ready. --- Cargo.lock | 140 ++++++++++++----------------------------------------- Cargo.toml | 7 +-- build.rs | 38 --------------- src/opt.rs | 36 +++++++------- 4 files changed, 49 insertions(+), 172 deletions(-) delete mode 100644 build.rs diff --git a/Cargo.lock b/Cargo.lock index 613a705..f31820a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -14,6 +14,17 @@ version = "4.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75054ce561491263d7b80dc2f6f6c6f8cdfd0c7a7c17c5cf3b8117829fa72ae1" +[[package]] +name = "atty" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" +dependencies = [ + "hermit-abi", + "libc", + "winapi", +] + [[package]] name = "autocfg" version = "1.1.0" @@ -40,24 +51,26 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" -version = "4.0.32" +version = "3.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7db700bc935f9e43e88d00b0850dae18a63773cfbec6d8e070fccf7fef89a39" +checksum = "71655c45cb9845d3270c9d6df84ebe72b4dad3c2ba3f7023ad47c144e4e473a5" dependencies = [ + "atty", "bitflags", "clap_derive", "clap_lex", - "is-terminal", + "indexmap", "once_cell", "strsim", "termcolor", + "textwrap", ] [[package]] name = "clap_derive" -version = "4.0.21" +version = "3.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0177313f9f02afc995627906bbd8967e2be069f5261954222dac78290c2b9014" +checksum = "ea0c8bce528c4be4da13ea6fead8965e95b6073585a2f05204bd8f4119f82a65" dependencies = [ "heck", "proc-macro-error", @@ -68,18 +81,18 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.3.0" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d4198f73e42b4936b35b5bb248d81d2b595ecb170da0bac7655c54eedfa8da8" +checksum = "2850f2f5a82cbf437dd5af4d49848fbdfc27c157c3d010345776f952765261c5" dependencies = [ "os_str_bytes", ] [[package]] name = "clap_mangen" -version = "0.2.6" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "904eb24d05ad587557e0f484ddce5c737c30cf81372badb16d13e41c4b8340b1" +checksum = "105180c05a72388d5f5e4e4f6c79eecb92497bda749fa8f963a16647c5d5377f" dependencies = [ "clap", "roff", @@ -170,9 +183,9 @@ checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" [[package]] name = "hermit-abi" -version = "0.2.6" +version = "0.1.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" +checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" dependencies = [ "libc", ] @@ -206,28 +219,6 @@ dependencies = [ "hashbrown", ] -[[package]] -name = "io-lifetimes" -version = "1.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "46112a93252b123d31a119a8d1a1ac19deac4fac6e0e8b0df58f0d4e5870e63c" -dependencies = [ - "libc", - "windows-sys", -] - -[[package]] -name = "is-terminal" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28dfb6c8100ccc63462345b67d1bbc3679177c75ee4bf59bf29c8b1d110b8189" -dependencies = [ - "hermit-abi", - "io-lifetimes", - "rustix", - "windows-sys", -] - [[package]] name = "itoa" version = "1.0.5" @@ -240,12 +231,6 @@ 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 = "log" version = "0.4.17" @@ -347,20 +332,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b833d8d034ea094b1ea68aa6d5c740e0d04bad9d16568d08ba6f76823a114316" -[[package]] -name = "rustix" -version = "0.36.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4feacf7db682c6c329c4ede12649cd36ecab0f3be5b7d74e6a20304725db4549" -dependencies = [ - "bitflags", - "errno", - "io-lifetimes", - "libc", - "linux-raw-sys", - "windows-sys", -] - [[package]] name = "ryu" version = "1.0.12" @@ -461,6 +432,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "textwrap" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" + [[package]] name = "thiserror" version = "1.0.38" @@ -556,60 +533,3 @@ 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_aarch64_gnullvm" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" - -[[package]] -name = "windows_i686_gnu" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" - -[[package]] -name = "windows_i686_msvc" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" diff --git a/Cargo.toml b/Cargo.toml index c8e95b5..599ed31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,12 +48,7 @@ scrawl="1.1.0" users="0.11" walkdir="2" number_prefix="0.4" -clap = { version = "4", features = ["derive"] } - -[build-dependencies] -clap_mangen="0.2" -clap = { version = "4", features = ["derive", "string"] } -anyhow = '1' +clap = { version = "3", features = ["derive"] } [dependencies.env_logger] default-features = false diff --git a/build.rs b/build.rs deleted file mode 100644 index 90acc94..0000000 --- a/build.rs +++ /dev/null @@ -1,38 +0,0 @@ -#[path = "src/opt.rs"] -#[allow(dead_code)] -mod opt; - -use clap::CommandFactory; -use std::path::Path; - -fn generate_command(man_path: &Path, cmd: &clap::Command) -> std::io::Result<()> { - let man = clap_mangen::Man::new(cmd.clone()); - let mut buffer: Vec = Default::default(); - man.render(&mut buffer)?; - - std::fs::write(man_path.join(format!("{}.1", cmd.get_name())), buffer)?; - - for sub in cmd.get_subcommands() { - let sub_name: String = format!("{}-{}", cmd.get_name(), sub.get_name()).to_string(); - generate_command(man_path, &sub.clone().name(sub_name))?; - } - - Ok(()) -} - -fn generate_man_page() -> std::io::Result<()> { - let current_dir = std::env::current_dir()?; - let man_path = current_dir.join("./target/man"); - std::fs::create_dir_all(&man_path)?; - - let cmd = opt::Opt::command(); - generate_command(&man_path, &cmd)?; - - Ok(()) -} - -fn main() -> std::io::Result<()> { - generate_man_page()?; - - Ok(()) -} diff --git a/src/opt.rs b/src/opt.rs index a884400..168f744 100644 --- a/src/opt.rs +++ b/src/opt.rs @@ -20,21 +20,21 @@ use std::str::FromStr; pub enum CacheCommand { /// Shows information about the cache directory for the script. Info { - #[arg(help = "A filename of the script file.")] + #[clap(help = "A filename of the script file.")] file: PathBuf, }, /// Clean the cache for a particular script. Removes the cache directory. Removes the Docker image/volume if /// they exist, but does not prune. - #[command(visible_alias = "clear")] + #[clap(visible_alias = "clear")] Clean { - #[arg(help = "A filename of the script file.")] + #[clap(help = "A filename of the script file.")] file: PathBuf, }, /// Shows a particular item from "info" by name. Get { - #[arg(help = "An item name, e.g. cache_path.")] + #[clap(help = "An item name, e.g. cache_path.")] name: String, - #[arg(help = "A filename of the script file.")] + #[clap(help = "A filename of the script file.")] file: PathBuf, }, } @@ -43,29 +43,29 @@ pub enum CacheCommand { pub enum TemplatesCommand { /// Imports a template from file. Import { - #[arg( + #[clap( help = "A filename of the script file. Extension will be stripped for the template name." )] file: PathBuf, }, /// Opens an editor to modify an existing template, nice for quick edits. Edit { - #[arg(help = "A name of the template to edit")] + #[clap(help = "A name of the template to edit")] template_name: String, }, /// Remove a custom template or reset it to the built-in contents. - #[command(name = "rm", visible_aliases = &["remove", "delete"])] + #[clap(name = "rm", visible_aliases = &["remove", "delete"])] Remove { - #[arg(help = "A name of the template to remove")] + #[clap(help = "A name of the template to remove")] template_name: String, }, /// List all templates. - #[command(name = "ls", visible_alias = "list")] + #[clap(name = "ls", visible_alias = "list")] List {}, } #[derive(Debug, PartialEq, Eq, Parser, Clone)] -#[command(rename_all = "snake-case")] +#[clap(rename_all = "snake-case")] pub enum BuildMode { Default, Source, @@ -97,17 +97,17 @@ impl FromStr for BuildMode { } #[derive(Debug, Parser, PartialEq, Eq)] -#[command( +#[clap( name = "scriptisto", about = "A 'shebang-interpreter' for compiled languages", args_conflicts_with_subcommands = true )] pub struct Opt { /// A path for to a script to run and additional arguments passed to this script. A script path must start with '.' or '/'. - #[arg(value_name = "SCRIPT")] + #[clap(value_name = "SCRIPT")] pub command: Vec, - #[command(subcommand)] + #[clap(subcommand)] pub cmd: Option, } @@ -121,23 +121,23 @@ pub enum Command { /// Prints an example starting script in a programming language of your /// choice. New { - #[arg( + #[clap( help = "If specified, determines a language. Example usage: \"scriptisto new | tee new-script\".\nIf not specified, \"new\" lists available templates." )] template_name: Option, }, /// Manage custom script templates. Template { - #[command(subcommand)] + #[clap(subcommand)] cmd: TemplatesCommand, }, /// Build a script without running. Build { /// A path to a script to build. - #[arg()] + #[clap()] script_src: String, /// Build mode. If unset, only builds if necessary. "source" - to rebuild each time. "full" to fully re-fetch Docker image and run `build_once_cmd`. - #[arg(short, long)] + #[clap(short, long)] build_mode: Option, }, }