1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! [![license badge][]][license link] [![rust badge]][rust link]
//!
//! # twilight-command-parser
//!
//! `twilight-command-parser` is a command parser for the [`twilight`] ecosystem.
//!
//! Included is a mutable configuration that allows you to specify the command
//! names and prefixes. The parser parses out commands matching an available
//! command and prefix and provides the command arguments to you.
//!
//! # Installation
//!
//! `twilight-command-parser` requires at least Rust 1.36.0.
//!
//! Add the following to your Cargo.toml:
//!
//! ```toml
//! [dependencies]
//! twilight-command-parser = "0.1"
//! ```
//!
//! ### Examples
//!
//! A simple parser for a bot with one prefix (`"!"`) and two commands: `"echo"`
//! and `"ping"`:
//!
//! ```rust,no_run
//! use twilight_command_parser::{Command, CommandParserConfig, Parser};
//!
//! let mut config = CommandParserConfig::new();
//!
//! // (Use `CommandParserConfig::add_command` to add a single command)
//! config.command("echo").add();
//! config.command("ping").add();
//!
//! // Add the prefix `"!"`.
//! // (Use `CommandParserConfig::add_prefixes` to add multiple prefixes)
//! config.add_prefix("!");
//!
//! let parser = Parser::new(config);
//!
//! // Now pass a command to the parser
//! match parser.parse("!echo a message") {
//!     Some(Command { name: "echo", arguments, .. }) => {
//!         let content = arguments.as_str();
//!
//!         println!("Got an echo request to send `{}`", content);
//!     },
//!     Some(Command { name: "ping", .. }) => {
//!         println!("Got a ping request");
//!     },
//!     // Ignore all other commands.
//!     Some(_) => {},
//!     None => println!("Message didn't match a prefix and command"),
//! }
//! ```
//!
//! [license badge]: https://img.shields.io/badge/license-ISC-blue.svg?style=flat-square
//! [license link]: https://opensource.org/licenses/ISC
//! [rust badge]: https://img.shields.io/badge/rust-1.36+-93450a.svg?style=flat-square
//! [rust link]: https://blog.rust-lang.org/2019/07/04/Rust-1.36.0.html
//! [`twilight`]: https://twilight.valley.cafe

#![deny(
    clippy::all,
    clippy::pedantic,
    future_incompatible,
    nonstandard_style,
    rust_2018_idioms,
    unused,
    warnings
)]
#![allow(clippy::module_name_repetitions, clippy::must_use_candidate)]

mod arguments;
mod builder;
mod casing;
mod config;
mod parser;

pub use self::{
    arguments::Arguments,
    builder::CommandBuilder,
    casing::CaseSensitivity,
    config::CommandParserConfig,
    parser::{Command, Parser},
};