[][src]Module dia_args::docs

Kit for documentation

Examples

use dia_args::docs::{Cfg, Cmd, Docs, I18n, Opt};

const CMD_HELP: &str = "help";
const CMD_HELP_DOCS: &str = "Prints help and exits.";

const CMD_VERSION: &str = "version";
const CMD_VERSION_DOCS: &str = "Prints version and exits.";

const CMD_DO_SOMETHING: &str = "do-something";
const CMD_DO_SOMETHING_DOCS: &str = 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: &str = "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: &str = "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_options = &[
    &Opt::new(ARG_THIS, false, None, Some(&ARG_THIS_DEFAULT), ARG_THIS_DOCS),
    &Opt::new(
        ARG_THAT, true, Some(dia_args::display!(ARG_THAT_VALUES)), Some(&ARG_THAT_DEFAULT),
        ARG_THAT_DOCS,
    ),
];
let do_something_cmd = Cmd::new(
    CMD_DO_SOMETHING, CMD_DO_SOMETHING_DOCS, Some(do_something_cmd_options),
);

let commands = &[&help_cmd, &version_cmd, &do_something_cmd];
let docs = Docs::new(
    // Name
    "The-Program",
    // Docs
    "This is the Program",
    // Configuration
    Cfg::default(),
    // Internatinonalization
    I18n::default(),
    // Program options
    None,
    // Commands
    Some(commands),
);
docs.print();

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

Structs

Cfg

Configuration

Cmd

Command

Docs

Documentation

I18n

Internatinonalization

Opt

Option