cmder/
lib.rs

1//! A simple, lighweight crate to parse command line arguments. Inspired by its javascript equivalent, commander.js.
2//!
3//! This crate is relatively similar in syntax to the said library and is easy to get started with. It presents a builder interface to work with and can easily be extended to suit your needs.
4//! The crate only offers a builder interface, no derive features, if you're looking such features or something more powerful, you should probably check out `clap`.
5//!
6//! Constructs used within the crate include:
7//! - Command, which is exactly what it sounds like
8//! - Program which is a command marked as the entrypoint
9//! - Flags and Options(flags that take arguments)
10//! - Themes that control the color choices used in the program
11//! - Patterns which control how output is formatted on the terminal
12//!
13//! The following is a full-fleged example on crate usage:
14//! ```
15//! use cmder::{Program, Event, Setting, Pattern, PredefinedThemes};
16//!
17//! let mut program = Program::new();
18//!
19//! program
20//!     .author("vndaba")
21//!     .description("An example CLI")
22//!     .version("0.1.0")
23//!     .bin_name("example");
24//!
25//! // Subcommands
26//! program
27//!     .subcommand("demo")
28//!     .argument("<value>", "Some required value")
29//!     .alias("d")
30//!     .option("-f", "Some flag")
31//!     .option("-n --name <value>", "Some option")
32//!     .description("A demo subcommand")
33//!     .action(|matches|{dbg!(matches);});
34//!
35//! // ...
36//!
37//! // Event listeners
38//! program.before_all(|cfg| {
39//!     let p_ref = cfg.get_program();
40//!     println!("This program was authored by: {}", p_ref.get_author())
41//! });
42//!
43//! // ...
44//!
45//! // Program settings
46//! program.set(Setting::ShowHelpOnAllErrors(true));
47//! program.set(Setting::ChoosePredefinedTheme(PredefinedThemes::Colorful));
48//! program.set(Setting::SetProgramPattern(Pattern::Standard));
49//! program.set(Setting::OverrideAllDefaultListeners(true));
50//!
51//! program.parse();
52//! ```
53//!
54//! While themes control the color palette used by the program, patterns on the hand control how the output is formatted as shown below:
55//!
56//! The default pattern used is the `Legacy` pattern which is how many CLIs act by default. This is how the output is formatted.
57//! ```bash
58//! $ cargo r -q --example subcommands -- -h
59//! An example of a program with subcommands
60//!
61//! USAGE:
62//!     docker [OPTIONS] <SUBCOMMAND>
63//!
64//! FLAGS:
65//!    -v, --version        Print out version information
66//!    -h, --help           Print out help information
67//!
68//! SUB-COMMANDS:
69//!    image                A command housing all the subcommands for image functionality
70//!    container            A command housing all subcommands for containers
71//!    help                 A subcommand used for printing out help
72//! ```
73//!
74//! This is the default pattern used by the program but can easily be changed by setting the program pattern to a different value.
75//!
76//! This will cause output to be formatted as follows:
77//! ```bash
78//! $ cargo r -q --example subcommands -- -h
79//! An example of a program with subcommands
80//!
81//! USAGE:
82//!     docker [OPTIONS] <SUBCOMMAND>
83//!
84//! FLAGS:
85//!     -v, --version
86//!       Print out version information
87//!     -h, --help
88//!       Print out help information
89//!
90//! SUB-COMMANDS:
91//!     image
92//!       A command housing all the subcommands for image functionality
93//!     container
94//!       A command housing all subcommands for containers
95//!     help
96//!       A subcommand used for printing out help
97//!
98//!
99//! ```
100//!
101//! You can also create your own custom-defined pattern. Refer to the `custom_pattern` example to see how this can be achieved.
102
103/// The parser modules contains all functionality for parsing arguments . It contains some submodules all involved in parsing arguments and flags.
104mod parse;
105
106/// A module housing all the core functionality of the library such as events, errors, settings and other core functionality
107mod core;
108
109/// A module to house some utilities used by the crate itself.
110mod utils;
111
112/// The UI module houses the formatter module that is used to print to stdout and the themes module used to construct and define new themes.
113mod ui;
114
115pub use crate::core::{Command, Event, EventEmitter, Program, Setting};
116pub use parse::{Argument, CmderFlag, CmderOption, ParserMatches};
117pub use termcolor::Color;
118pub use ui::{CustomPattern, Designation, Formatter, Pattern, PredefinedThemes, Theme};