cl_parse/lib.rs
1//! # Command Line Parse
2//!
3//! `cl_parse` is a library that allows you to define commandline options and arguments and then
4//! parse the commandline arguments based on that definition.
5//!
6//! # Motivation
7//!
8//! `cl_parse` was developed to allow the most common commandline options that are used in
9//! modern commandline utilities. It was also designed for ease of use. The following are the features
10//! implemented in cl_parse.
11//!
12//! - option aliases. e.g. -f, --file
13//! - options with negative values. e.g. --increment -1
14//! - flag concatenation. i.e. -xvgf is equivalent to -x -v -g -f
15//! - Auto usage message generation
16//! - Auto help message generation
17//! - -h, --help output provided by default
18//! - missing value detection for options
19//! - ability to define required options
20//! - option and argument validation. i.e. only defined options and arguments can be used
21//! - unordered options and arguments
22//! - retrieving the option or argument in the target type. e.g. i32, String, etc.
23//!
24//! # Examples
25//!
26#![deny(missing_docs)]
27
28const SHORT_OPTION: &'static str = "-";
29const LONG_OPTION: &'static str = "--";
30const SHORT_HELP: &'static str = "-h";
31const LONG_HELP: &'static str = "--help";
32const TRUE: &'static str = "true";
33const FALSE: &'static str = "false";
34
35/// # Option Def
36///
37/// `option_def` is used by cl_def to define options
38mod option_def;
39
40/// # Command Line Def
41///
42/// `cl_def` is used to define and parse commandline options and arguments
43mod cl_def;
44
45/// # Command Line
46///
47/// `command_line` is a collection of utilities for processing commandline arguments
48mod command_line;
49
50pub use cl_def::CommandLineDef;
51pub use command_line::CommandLine;
52
53mod text;
54
55#[inline]
56fn format_usage(msg: &str, usage: &str) -> String {
57 format!("{}\n{}", msg, usage)
58}
59
60#[inline]
61fn panic_msg(msg: String) {
62 panic!("{}",msg)
63}
64