set up structure for multiple cli commands

The previous cli is now behind the 'serve' subcommand.
This commit is contained in:
Benjamin Lee 2024-08-31 20:51:26 -07:00
parent 1ee3bbb316
commit be87774a3b
No known key found for this signature in database
GPG key ID: FB9624E2885D55A4
4 changed files with 60 additions and 39 deletions

51
src/cli.rs Normal file
View file

@ -0,0 +1,51 @@
//! Integration with `clap`
use std::path::PathBuf;
use clap::{Parser, Subcommand};
/// Command line arguments
#[derive(Parser)]
#[clap(
about,
version = crate::version(),
)]
pub(crate) struct Args {
#[clap(subcommand)]
pub(crate) command: Command,
}
#[derive(Subcommand)]
pub(crate) enum Command {
/// Run the server.
Serve(ServeArgs),
}
/// Wrapper for the `--config` arg.
///
/// This exists to centralize the `mut_arg` code that sets the help value based
/// on runtime information.
#[derive(clap::Args)]
#[clap(mut_arg("config", |x| {
let help = "Set the path to the configuration file";
x.help(help).long_help(format!(
"{}\n\nIf this option is specified, the provided value is used \
as-is.\n\nIf this option is not specified, then the XDG Base \
Directory Specification is followed, searching for the path `{}` \
in the configuration directories.
",
help,
crate::config::DEFAULT_PATH.display(),
))
}))]
pub(crate) struct ConfigArg {
/// Path to the configuration file
#[clap(long, short)]
pub(crate) config: Option<PathBuf>,
}
#[derive(clap::Args)]
pub(crate) struct ServeArgs {
#[clap(flatten)]
pub(crate) config: ConfigArg,
}