Add docs for the CLI module
This commit is contained in:
+43
-3
@@ -1,3 +1,43 @@
|
|||||||
|
//! Payphone's main entry point, which initializes the bot and starts the event loop.
|
||||||
|
//!
|
||||||
|
//! This module is responsible for parsing command line arguments, nothing else.
|
||||||
|
//!
|
||||||
|
//! # Command Line Arguments
|
||||||
|
//!
|
||||||
|
//! The command line arguments are parsed using the [`clap`] crate, and can be found in the
|
||||||
|
//! [`Args`] struct. The arguments are:
|
||||||
|
//!
|
||||||
|
//! - `--token` or `-t`: The Discord bot token to run the bot with. This is required.
|
||||||
|
//! - `--logging` or `-l`: The minimum level logs have to be to be outputted into the console, or
|
||||||
|
//! off for no logs. Defaults to `info`.
|
||||||
|
//! - `--database-addr` or `-d`: The address of the database to connect to, a Scylla node.
|
||||||
|
//!
|
||||||
|
//! The CLI also supports setting argument values via environment variables. The environment
|
||||||
|
//! variables are prefixed with `PAYPHONE_`, so for example, the `--token` argument can be set
|
||||||
|
//! using the `PAYPHONE_TOKEN` environment variable. The environment variables are used to
|
||||||
|
//! override the command line arguments. `.env` files are also supported by default, so you can
|
||||||
|
//! create a `.env` file in the root of the project with the following content:
|
||||||
|
//!
|
||||||
|
//! ```env
|
||||||
|
//! PAYPHONE_TOKEN="your_discord_bot_token"
|
||||||
|
//! PAYPHONE_LOGGING="info"
|
||||||
|
//! PAYPHONE_DATABASE_ADDR="your_database_addr"
|
||||||
|
//! ```
|
||||||
|
//!
|
||||||
|
//! # Parsing Arguments
|
||||||
|
//!
|
||||||
|
//! The arguments are parsed using the [`Args::parse`] method, which returns an instance of the
|
||||||
|
//! [`Args`] struct. This struct contains the parsed values of the command line arguments, and
|
||||||
|
//! can be used to initialize the bot and start the event loop.
|
||||||
|
//!
|
||||||
|
//! ```
|
||||||
|
//! // Read the environment variables from the `.env` file, if it exists, and load them as proper
|
||||||
|
//! // env variables.
|
||||||
|
//! dotenvy::dotenv().ok();
|
||||||
|
//!
|
||||||
|
//! let args = Args::parse();
|
||||||
|
//! ```
|
||||||
|
|
||||||
#[derive(clap::Parser)]
|
#[derive(clap::Parser)]
|
||||||
pub struct Args {
|
pub struct Args {
|
||||||
/// The Discord bot token to run the bot with.
|
/// The Discord bot token to run the bot with.
|
||||||
@@ -18,11 +58,11 @@ pub struct Args {
|
|||||||
#[arg(
|
#[arg(
|
||||||
long,
|
long,
|
||||||
short,
|
short,
|
||||||
env = "PAYPHONE_DATABASE_URL",
|
env = "PAYPHONE_DATABASE_ADDR",
|
||||||
value_name = "URL",
|
value_name = "ADDR",
|
||||||
default_value_t = String::from("127.0.0.1:9042"))
|
default_value_t = String::from("127.0.0.1:9042"))
|
||||||
]
|
]
|
||||||
pub database_url: String,
|
pub database_addr: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
|
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
|
||||||
|
|||||||
+1
-1
@@ -117,7 +117,7 @@ pub async fn main() {
|
|||||||
env!("CARGO_PKG_VERSION")
|
env!("CARGO_PKG_VERSION")
|
||||||
);
|
);
|
||||||
|
|
||||||
let db = database::init(args.database_url)
|
let db = database::init(args.database_addr)
|
||||||
.await
|
.await
|
||||||
.expect("Could not connect to the database!");
|
.expect("Could not connect to the database!");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user