-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathlib.rs
More file actions
68 lines (57 loc) · 2.04 KB
/
Copy pathlib.rs
File metadata and controls
68 lines (57 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
//! ## `humility doc`
//!
//! Provides detailed documentation for Humility and its commands. To
//! get documentation on Humility, run `humility doc`; to get documentation
//! for a specific command (like this one!) run `humility doc` and specify
//! the command name -- and run `humility --help` to list all commands.
//!
use anyhow::{Result, bail};
use clap::{CommandFactory, Parser};
use humility_cli::ExecutionContext;
use humility_cmd::Command;
use std::collections::HashMap;
use termimad::*;
include!(concat!(env!("OUT_DIR"), "/docs.rs"));
#[derive(Parser, Debug)]
#[clap(name = "doc", about = env!("CARGO_PKG_DESCRIPTION"))]
struct DocArgs {
/// Humility command for which to get documentation
#[clap(value_name = "command")]
command: Option<String>,
}
fn doc(context: &mut ExecutionContext) -> Result<()> {
let subargs = DocArgs::try_parse_from(&context.cli.cmd)?;
let text = match subargs.command {
Some(ref cmd) => match cmd_docs(cmd) {
Some(text) => text,
None => {
bail!(
"unrecognized command \"{}\"; run \
\"humility --help\" for list",
cmd
);
}
},
None => docs(),
};
let options = minimad::Options::default().continue_spans(true);
let text = minimad::parse_text(text, options);
let mut skin = MadSkin::default();
skin.table.align = Alignment::Center;
skin.code_block.align = Alignment::Center;
let text = FmtText::from_text(&skin, text, Some(80));
println!("{}", &text);
if let Some(ref cmd) = subargs.command {
skin.print_text(&format!(
"For all command line flags, run `humility {} --help`.",
cmd
));
}
Ok(())
}
pub fn init() -> Command {
Command { app: DocArgs::command(), name: "doc", run: doc }
}