diff --git a/Cargo.lock b/Cargo.lock index d08734ead..9191f93fd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -367,6 +367,15 @@ dependencies = [ "clap_derive", ] +[[package]] +name = "clap-markdown" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "325f50228f76921784b6d9f2d62de6778d834483248eefecd27279174797e579" +dependencies = [ + "clap", +] + [[package]] name = "clap_builder" version = "4.4.18" @@ -1578,6 +1587,7 @@ dependencies = [ "cargo_metadata", "chrono", "clap", + "clap-markdown", "clap_complete", "clap_mangen", "config", diff --git a/Cargo.toml b/Cargo.toml index 6b5731e2e..c6d4b8683 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -32,6 +32,7 @@ clap = { version = "4.4.18", features = [ "string", ] } clap_complete = "4.4.9" +clap-markdown = "0.1.3" clap_mangen = "0.2.10" chrono = { version = "0.4.33", default-features = false, features = [ "std", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index f6b1ab76a..241b95a88 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -32,6 +32,7 @@ cargo_metadata = { workspace = true } [dependencies] chrono = { workspace = true } clap = { workspace = true } +clap-markdown = { workspace = true } clap_complete = { workspace = true } clap_mangen = { workspace = true } config = { workspace = true } diff --git a/cli/src/commands/util.rs b/cli/src/commands/util.rs index 4c0d9c7cf..f1c790a5b 100644 --- a/cli/src/commands/util.rs +++ b/cli/src/commands/util.rs @@ -29,6 +29,7 @@ pub(crate) enum UtilCommand { Completion(UtilCompletionArgs), Gc(UtilGcArgs), Mangen(UtilMangenArgs), + MarkdownHelp(UtilMarkdownHelp), ConfigSchema(UtilConfigSchemaArgs), } @@ -79,6 +80,10 @@ pub(crate) struct UtilGcArgs { #[derive(clap::Args, Clone, Debug)] pub(crate) struct UtilMangenArgs {} +/// Print the CLI help for all subcommands in Markdown +#[derive(clap::Args, Clone, Debug)] +pub(crate) struct UtilMarkdownHelp {} + /// Print the JSON schema for the jj TOML config format. #[derive(clap::Args, Clone, Debug)] pub(crate) struct UtilConfigSchemaArgs {} @@ -93,6 +98,7 @@ pub(crate) fn cmd_util( UtilCommand::Completion(args) => cmd_util_completion(ui, command, args), UtilCommand::Gc(args) => cmd_util_gc(ui, command, args), UtilCommand::Mangen(args) => cmd_util_mangen(ui, command, args), + UtilCommand::MarkdownHelp(args) => cmd_util_markdownhelp(ui, command, args), UtilCommand::ConfigSchema(args) => cmd_util_config_schema(ui, command, args), } } @@ -152,6 +158,18 @@ fn cmd_util_mangen( Ok(()) } +fn cmd_util_markdownhelp( + ui: &mut Ui, + command: &CommandHelper, + _args: &UtilMarkdownHelp, +) -> Result<(), CommandError> { + // If we ever need more flexibility, the code of `clap_markdown` is simple and + // readable. We could reimplement the parts we need without trouble. + let markdown = clap_markdown::help_markdown_command(command.app()).into_bytes(); + ui.stdout_formatter().write_all(&markdown)?; + Ok(()) +} + fn cmd_util_config_schema( ui: &mut Ui, _command: &CommandHelper,