Debian Codegraph @

cli/src/commands/util/markdown_help.rs

raw
1 // Copyright 2020 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use std::io::Write as _;
16
17 use crate::cli_util::CommandHelper;
18 use crate::command_error::CommandError;
19 use crate::ui::Ui;
20
21 /// Print the CLI help for all subcommands in Markdown
22 #[derive(clap::Args, Clone, Debug)]
23 pub struct UtilMarkdownHelp {}
24
25 pub async fn cmd_util_markdown_help(
26 ui: &mut Ui,
27 command: &CommandHelper,
28 _args: &UtilMarkdownHelp,
29 ) -> Result<(), CommandError> {
30 // If we ever need more flexibility, the code of `clap_markdown` is simple and
31 // readable. We could reimplement the parts we need without trouble.
32 let markdown = clap_markdown::help_markdown_command(command.app()).into_bytes();
33 ui.stdout().write_all(&markdown)?;
34 Ok(())
35 }