mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 15:51:23 +01:00
set up structure for multiple cli commands
The previous cli is now behind the 'serve' subcommand.
This commit is contained in:
parent
1ee3bbb316
commit
be87774a3b
4 changed files with 60 additions and 39 deletions
51
src/cli.rs
Normal file
51
src/cli.rs
Normal 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,
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue