[][src]Module dia_args::docs

Kit for documentation

Examples

use std::borrow::Cow;
use dia_args::docs::{self, Cfg, Cmd, Docs, I18n, Opt, 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 ARG_THIS: &[&str] = &["-t", "--this"];
const ARG_THIS_DEFAULT: bool = true;
const ARG_THIS_DOCS: Cow<str> = Cow::Borrowed("This argument has 2 names.");

const ARG_THAT: &[&str] = &["--that"];
const ARG_THAT_VALUES: &[u8] = &[99, 100];
const ARG_THAT_DEFAULT: u8 = ARG_THAT_VALUES[0];
const ARG_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_opts![
        Opt::new(ARG_THIS, false, None, Some(&ARG_THIS_DEFAULT), ARG_THIS_DOCS),
        Opt::new(
            ARG_THAT, true,
            Some(docs::make_cow_strings(ARG_THAT_VALUES)), Some(&ARG_THAT_DEFAULT),
            ARG_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("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

Opt

Option

Project

Project information

Functions

make_cow_strings

Makes a vector of Cow<'_, str> from input slice of Display's