Add docs server

This commit is contained in:
2025-08-10 22:50:55 -03:00
parent 1f002cb7ca
commit edeaa1335f
5 changed files with 419 additions and 27 deletions
+55 -18
View File
@@ -23,28 +23,26 @@
//! 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();
//! ```
/// Payphone's argument parser.
#[derive(clap::Parser)]
#[command(name = "Payphone CLI")]
#[command(version, about = "Payphone's command line interface.")]
pub struct Args {
/// The Discord bot token to run the bot with.
#[arg(env = "PAYPHONE_TOKEN")]
pub token: String,
/// The minimum level logs have to be to be outputted into the console, or off for no logs.
#[arg(
long,
@@ -57,28 +55,33 @@ pub struct Args {
)]
pub logging: LevelFilter,
/// The socket address of the database to connect to, a Scylla node.
#[arg(
long,
short,
env = "PAYPHONE_DATABASE_ADDR",
value_name = "ADDR",
default_value_t = String::from("127.0.0.1:9042"))
]
pub database_addr: String,
#[command(subcommand)]
pub command: Option<Commands>,
}
/// An enum with the different logging levels that can be used in the CLI.
///
///
/// This enum is used to parse the `--logging` or `-l` command line argument and then map the value
/// to [`log::LevelFilter`].
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, clap::ValueEnum)]
pub enum LevelFilter {
/// No logs at all.
Off,
/// The most verbose level, used for debugging purposes.
Trace,
/// Events that are useful to be displayed during development, but not in production.
Debug,
/// Used for general information about the bot's state and milestones.
Info,
/// Used for warnings, when something unexpected happens but the bot can still continue
/// running.
Warn,
/// Used for errors, when something goes wrong and the bot cannot continue running.
Error,
}
@@ -95,3 +98,37 @@ impl Into<log::LevelFilter> for LevelFilter {
}
}
}
#[derive(clap::Subcommand, Clone)]
pub enum Commands {
/// Starts the bot with the provided token.
Start {
/// The Discord bot token to run the bot with.
#[arg(env = "PAYPHONE_TOKEN")]
token: String,
/// The socket address of the database to connect to, a Scylla node.
#[arg(
long,
short,
env = "PAYPHONE_DATABASE_ADDR",
value_name = "ADDR",
default_value_t = String::from("127.0.0.1:9042"))
]
database_addr: String,
},
/// Starts a documentation server for the project which serves `cargo doc` and refreshes on
/// changes.
Docs {
/// The port to run the documentation server on.
#[arg(
long,
short,
env = "PAYPHONE_DOCS_PORT",
value_name = "PORT",
default_value_t = 3000
)]
port: u16,
},
}