diff --git a/Cargo.lock b/Cargo.lock index f01746c..ccd834c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,173 +1,222 @@ -[[package]] -name = "ansi_term" -version = "0.11.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", -] +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 [[package]] name = "atty" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "termion", + "winapi", ] [[package]] -name = "bitflags" -version = "0.9.1" +name = "autocfg" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] name = "bitflags" -version = "1.0.3" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "clap" -version = "3.0.0-alpha1" -source = "git+https://github.com/kbknapp/clap-rs?branch=v3-dev#6a99e638f7ba10b104a843ac39a6e38bb70ad9dd" +version = "3.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c167e37342afc5f33fd87bbc870cedd020d2a6dffa05d45ccd9241fbdd146db" dependencies = [ - "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "atty", + "bitflags", + "clap_lex", + "indexmap", + "strsim", + "termcolor", + "textwrap", ] [[package]] name = "clap-md" version = "0.1.0" dependencies = [ - "clap 3.0.0-alpha1 (git+https://github.com/kbknapp/clap-rs?branch=v3-dev)", - "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "pulldown-cmark-to-cmark 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "clap", + "pulldown-cmark", + "pulldown-cmark-to-cmark", +] + +[[package]] +name = "clap_lex" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "189ddd3b5d32a70b35e7686054371742a937b0d99128e76dde6340210e966669" +dependencies = [ + "os_str_bytes", ] [[package]] name = "getopts" version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" dependencies = [ - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width", ] +[[package]] +name = "hashbrown" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" + [[package]] name = "indexmap" -version = "1.0.1" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f647032dfaa1f8b6dc29bd3edb7bbef4861b8b8007ebb118d6db284fd59f6ee" +dependencies = [ + "autocfg", + "hashbrown", +] [[package]] name = "libc" version = "0.2.42" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" + +[[package]] +name = "memchr" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" + +[[package]] +name = "os_str_bytes" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e22443d1643a904602595ba1cd8f7d896afe56d26712531c5ff73a15b2fbf64" [[package]] name = "pulldown-cmark" -version = "0.1.2" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "34f197a544b0c9ab3ae46c359a7ec9cbbb5c7bf97054266fecb7ead794a181d6" dependencies = [ - "bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", - "getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags", + "getopts", + "memchr", + "unicase", ] [[package]] name = "pulldown-cmark-to-cmark" -version = "1.1.0" +version = "10.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3eafb76310f7dc895b5d83d24f2a00e244fc8a68ef94f4257eb4060984d0385f" dependencies = [ - "pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "pulldown-cmark", ] [[package]] name = "redox_syscall" version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" [[package]] name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" dependencies = [ - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall", ] [[package]] name = "strsim" -version = "0.7.0" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] +name = "termcolor" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +dependencies = [ + "winapi-util", +] [[package]] name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" dependencies = [ - "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc", + "redox_syscall", + "redox_termios", ] [[package]] name = "textwrap" -version = "0.10.0" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" + +[[package]] +name = "unicase" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" dependencies = [ - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check", ] [[package]] name = "unicode-width" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" [[package]] -name = "vec_map" -version = "0.8.1" +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.5" source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" dependencies = [ - "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "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" - -[metadata] -"checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" -"checksum bitflags 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4efd02e230a02e18f92fc2735f44597385ed02ad8f831e7c1c1156ee5e1ab3a5" -"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" -"checksum clap 3.0.0-alpha1 (git+https://github.com/kbknapp/clap-rs?branch=v3-dev)" = "" -"checksum getopts 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "0a7292d30132fb5424b354f5dc02512a86e4c516fe544bb7a25e7f266951b797" -"checksum indexmap 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08173ba1e906efb6538785a8844dd496f5d34f0a2d88038e95195172fc667220" -"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" -"checksum pulldown-cmark 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d6fdf85cda6cadfae5428a54661d431330b312bc767ddbc57adbedc24da66e32" -"checksum pulldown-cmark-to-cmark 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "57efca5f52f63336ee3a49bceee1a1169f18ef01c75aa7e71949441b49bbe7e4" -"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" -"checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" -"checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" -"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" -"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" -"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" -"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" -"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" -"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 03d7f95..05de9f8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,6 +9,6 @@ description = "Generate Markdown documentation for clap application definitions" readme = "README.md" [dependencies] -clap = { git = "https://github.com/kbknapp/clap-rs", branch = "v3-dev" } -pulldown-cmark = "0.1.2" -pulldown-cmark-to-cmark = "1.1.0" +clap = "3.1.8" +pulldown-cmark = "0.9.1" +pulldown-cmark-to-cmark = "10.0.1" diff --git a/examples/testapp.rs b/examples/testapp.rs index 603bbc9..47e27d5 100644 --- a/examples/testapp.rs +++ b/examples/testapp.rs @@ -3,20 +3,20 @@ extern crate clap; extern crate clap_md; -use clap::{App, AppSettings, Arg, SubCommand}; +use clap::{Arg, Command}; use clap_md::app_to_md; fn main() { - let a = App::new("testapp") + let a = Command::new("testapp") .about("Pointless application") - .setting(AppSettings::SubcommandRequiredElseHelp) + .arg_required_else_help(true) + .subcommand_required(true) .author("Katharina Fey ") - // .author("Yosh Wuyts (Vec>); impl<'a> Document<'a> { fn header(&mut self, text: String, level: i32) { - self.0.push(Event::Start(Tag::Header(level))); + let level = match level { + 1 => HeadingLevel::H1, + 2 => HeadingLevel::H2, + 3 => HeadingLevel::H3, + 4 => HeadingLevel::H4, + 5 => HeadingLevel::H5, + 6 => HeadingLevel::H6, + _ => panic!("nope"), + }; + self.0 + .push(Event::Start(Tag::Heading(level, None, Vec::new()))); self.0.push(Event::Text(text.into())); - self.0.push(Event::End(Tag::Header(level))); + self.0 + .push(Event::End(Tag::Heading(level, None, Vec::new()))); } fn paragraph(&mut self, text: String) { @@ -22,65 +33,58 @@ impl<'a> Document<'a> { } } -fn recursive(doc: &mut Document, app: &App, level: i32, skip_header: bool) { +fn recursive(doc: &mut Document, app: &Command, level: i32, skip_header: bool) { if !skip_header { - doc.header(app.name.clone(), level); + doc.header(app.get_name().into(), level); } - if let Some(about) = app.about { + if let Some(about) = app.get_about() { doc.paragraph(about.into()); } - if let Some(author) = app.author { + if let Some(author) = app.get_author() { doc.paragraph(format!("Author: {}", author)); } - if let Some(version) = app.version_short { - let msg = if let Some(msg) = app.version_message { - format!(" ({})", msg) - } else { - "".into() - }; - doc.paragraph(format!("Version: {}{}", version, msg)); + if let Some(version) = app.get_version().or_else(|| app.get_long_version()) { + doc.paragraph(format!("Version: {}", version)); } - if !app.args.is_empty() { + if app.get_arguments().any(|_| true) { doc.paragraph("Arguments:".into()); doc.0.push(Event::Start(Tag::List(None))); - for arg in &app.args { + for arg in app.get_arguments() { doc.0.push(Event::Start(Tag::Item)); doc.0.push(Event::Start(Tag::Paragraph)); - doc.0.push(Event::Start(Tag::Code)); - let mut def = String::new(); - if let Some(short) = arg.short { + if let Some(short) = arg.get_short() { def.push_str("-"); def.push(short); } - if let Some(long) = arg.long { - if arg.short.is_some() { + if let Some(long) = arg.get_long() { + if arg.get_short().is_some() { def.push_str("/"); } def.push_str("--"); def.push_str(long); } - if arg.is_set(ArgSettings::TakesValue) { + if arg.is_takes_value_set() { def.push_str("=<"); - def.push_str(arg.name); + def.push_str(arg.get_value_names().unwrap().join(",").as_str()); def.push_str(">"); } - doc.0.push(Event::Text(def.into())); - doc.0.push(Event::End(Tag::Code)); + doc.0.push(Event::Code(def.into())); let mut text = String::new(); - if let Some(help) = arg.help { - if arg.short.is_some() || arg.long.is_some() { + if let Some(help) = arg.get_help() { + if arg.get_short().is_some() || arg.get_long().is_some() { text.push_str(": "); } text.push_str(help); } + doc.0.push(Event::Text(text.into())); doc.0.push(Event::End(Tag::Paragraph)); @@ -90,10 +94,10 @@ fn recursive(doc: &mut Document, app: &App, level: i32, skip_header: bool) { doc.0.push(Event::End(Tag::List(None))); } - if !app.subcommands.is_empty() { + if app.get_subcommands().any(|_| true) { doc.header("Subcommands".into(), level + 1); - for cmd in &app.subcommands { + for cmd in app.get_subcommands() { recursive(doc, cmd, level + 2, false); } } @@ -107,13 +111,10 @@ fn recursive(doc: &mut Document, app: &App, level: i32, skip_header: bool) { /// - `level`: The level for first markdown headline. If you for example want to /// render this beneath a `## Usage` headline in your readme, you'd want to /// set `level` to `2`. -pub fn app_to_md<'a, 'b>( - app: &App<'a, 'b>, - level: i32, -) -> Result> { +pub fn app_to_md(app: Command, level: i32) -> Result> { let mut document = Document(Vec::new()); - recursive(&mut document, app, level, level > 1); + recursive(&mut document, &app, level, level > 1); let mut result = String::new(); - cmark(document.0.iter(), &mut result, None)?; + cmark(document.0.iter(), &mut result)?; Ok(result) }