follow xdg base dirs spec by default

This commit is contained in:
Charles Hall 2024-06-11 20:41:05 -07:00
parent c46eaed0e0
commit 85e77832e9
No known key found for this signature in database
GPG key ID: 7B8E0645816E07CF
6 changed files with 69 additions and 7 deletions

View file

@ -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(),
}
}