Module docs

Module docs 

Source
Expand description

§Kit for documentation

§Examples

use std::borrow::Cow;
use dia_args::docs::{self, Cfg, Cmd, Docs, I18n, Option, Project};

const CMD_HELP: &str = "help";
const CMD_HELP_DOCS: Cow<str> = Cow::Borrowed("Prints help and exits.");

const CMD_VERSION: &str = "version";
const CMD_VERSION_DOCS: Cow<str> = Cow::Borrowed("Prints version and exits.");

const CMD_DO_SOMETHING: &str = "do-something";
const CMD_DO_SOMETHING_DOCS: Cow<str> = Cow::Borrowed(concat!(
    "This command does something.\n",
    "\n",
    "It might NOT do that thing. If you encounter any problems,",
    " please contact developers.\n",
));

const OPTION_THIS: &[&str] = &["-t", "--this"];
const OPTION_THIS_DEFAULT: bool = true;
const OPTION_THIS_DOCS: Cow<str> = Cow::Borrowed("This argument has 2 names.");

const OPTION_THAT: &[&str] = &["--that"];
const OPTION_THAT_VALUES: &[u8] = &[99, 100];
const OPTION_THAT_DEFAULT: u8 = OPTION_THAT_VALUES[0];
const OPTION_THAT_DOCS: Cow<str> = Cow::Borrowed("This argument has 1 single name.");

let help_cmd = Cmd::new(CMD_HELP, CMD_HELP_DOCS, None);
let version_cmd = Cmd::new(CMD_VERSION, CMD_VERSION_DOCS, None);
let do_something_cmd = Cmd::new(
    CMD_DO_SOMETHING, CMD_DO_SOMETHING_DOCS,
    Some(dia_args::make_options![
        Option::new(OPTION_THIS, false, &[], Some(OPTION_THIS_DEFAULT), OPTION_THIS_DOCS),
        Option::new(OPTION_THAT, true, OPTION_THAT_VALUES, Some(OPTION_THAT_DEFAULT), OPTION_THAT_DOCS),
    ]),
);

let mut docs = Docs::new(
    // Name
    "The-Program".into(),
    // Docs
    "This is the Program".into(),
);
docs.commands = Some(dia_args::make_cmds![help_cmd, version_cmd, do_something_cmd,]);
docs.project = Some(Project::new(Some("https://project-home"), "Nice License", None));
docs.print()?;

// This does the same as above command:
// println!("{}", docs);

Structs§

Cfg
Configuration
Cmd
Command
Docs
Documentation
I18n
Internatinonalization
Option
Option
Project
Project information

Constants§

NO_VALUES
No values