Add docs for the CLI module

This commit is contained in:
2025-08-10 21:52:14 -03:00
parent d444a4ab89
commit 6ca2649840
2 changed files with 68 additions and 28 deletions
+43 -3
View File
@@ -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)]
pub struct Args {
/// The Discord bot token to run the bot with.
@@ -18,11 +58,11 @@ pub struct Args {
#[arg(
long,
short,
env = "PAYPHONE_DATABASE_URL",
value_name = "URL",
env = "PAYPHONE_DATABASE_ADDR",
value_name = "ADDR",
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)]