summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-01-17 08:05:43 +0200
committerLars Wirzenius <liw@liw.fi>2021-01-17 08:05:43 +0200
commit06b5606f13592b669212a97fb5ea3367d7f0fa21 (patch)
treec0c9080d79bf5cc9972b50a562e31ba822abbe05 /src/bin
parent6d53680f71d7d88bb9498c75db95bfb1408c6fc7 (diff)
downloadobnam2-06b5606f13592b669212a97fb5ea3367d7f0fa21.tar.gz
feat: add a default configuration file
The ~/.config/obnam/obnam.yaml file will be used as the configuration file by default. The ~/.config directory can be overridden by setting the XDG variable (XDG_CONFIG_HOME), or the whole file can be overridden with the --config option to obnam.
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/obnam.rs18
1 files changed, 16 insertions, 2 deletions
diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs
index 1e09168..e9f30ca 100644
--- a/src/bin/obnam.rs
+++ b/src/bin/obnam.rs
@@ -10,7 +10,11 @@ const BUFFER_SIZE: usize = 1024 * 1024;
fn main() -> anyhow::Result<()> {
let opt = Opt::from_args();
- let config = ClientConfig::read_config(&opt.config)?;
+ let config_file = match opt.config {
+ None => default_config(),
+ Some(ref path) => path.to_path_buf(),
+ };
+ let config = ClientConfig::read_config(&config_file)?;
if let Some(ref log) = config.log {
setup_logging(&log)?;
}
@@ -37,11 +41,21 @@ fn main() -> anyhow::Result<()> {
Ok(())
}
+fn default_config() -> PathBuf {
+ if let Some(path) = dirs::config_dir() {
+ path.join("obnam").join("obnam.yaml")
+ } else if let Some(path) = dirs::home_dir() {
+ path.join(".config").join("obnam").join("obnam.yaml")
+ } else {
+ panic!("can't find config dir or home dir");
+ }
+}
+
#[derive(Debug, StructOpt)]
#[structopt(name = "obnam-backup", about = "Simplistic backup client")]
struct Opt {
#[structopt(long, short, parse(from_os_str))]
- config: PathBuf,
+ config: Option<PathBuf>,
#[structopt(subcommand)]
cmd: Command,