mirror of
https://gitlab.computer.surgery/matrix/grapevine.git
synced 2025-12-17 07:41:23 +01:00
follow xdg base dirs spec by default
This commit is contained in:
parent
c46eaed0e0
commit
85e77832e9
6 changed files with 69 additions and 7 deletions
22
src/args.rs
22
src/args.rs
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
use clap::{CommandFactory as _, FromArgMatches as _, Parser};
|
||||
|
||||
/// Command line arguments
|
||||
#[derive(Parser)]
|
||||
|
|
@ -10,10 +10,26 @@ use clap::Parser;
|
|||
pub(crate) struct Args {
|
||||
/// Path to the configuration file
|
||||
#[clap(long, short)]
|
||||
pub(crate) config: PathBuf,
|
||||
pub(crate) config: Option<PathBuf>,
|
||||
}
|
||||
|
||||
/// Parse command line arguments into structured data
|
||||
pub(crate) fn parse() -> Args {
|
||||
Args::parse()
|
||||
let mut command = Args::command().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(),
|
||||
))
|
||||
});
|
||||
|
||||
match Args::from_arg_matches(&command.get_matches_mut()) {
|
||||
Ok(x) => x,
|
||||
Err(e) => e.format(&mut command).exit(),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue