summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-04-10 10:10:20 +0300
committerLars Wirzenius <liw@liw.fi>2021-04-10 10:29:27 +0300
commit9243bc30891fc9db615560da8af83cf715664d9a (patch)
treee3ab9a5affb151993fc9caf895b5c924ffc552d4
parent958839c264b3ef36ef1bc74a4794fc383cc39292 (diff)
downloadobnam2-9243bc30891fc9db615560da8af83cf715664d9a.tar.gz
refactor: have ClientConfigWithoutPasswords know its filename
This allows Init::run to not need to be given it as an argument.
-rw-r--r--src/bin/obnam.rs3
-rw-r--r--src/cmd/init.rs9
-rw-r--r--src/config.rs2
3 files changed, 5 insertions, 9 deletions
diff --git a/src/bin/obnam.rs b/src/bin/obnam.rs
index 0f3da30..4f4cd5b 100644
--- a/src/bin/obnam.rs
+++ b/src/bin/obnam.rs
@@ -27,9 +27,8 @@ fn main() -> anyhow::Result<()> {
debug!("{:?}", opt);
debug!("configuration: {:#?}", config);
- let cfgname = config_filename(&opt);
let result = if let Command::Init(init) = opt.cmd {
- init.run(config.config(), &cfgname)
+ init.run(config.config())
} else {
let config = load_config_with_passwords(&opt)?;
match opt.cmd {
diff --git a/src/cmd/init.rs b/src/cmd/init.rs
index 462174e..cb61fba 100644
--- a/src/cmd/init.rs
+++ b/src/cmd/init.rs
@@ -1,7 +1,6 @@
use crate::config::ClientConfigWithoutPasswords;
use crate::error::ObnamError;
use crate::passwords::{passwords_filename, Passwords};
-use std::path::Path;
use structopt::StructOpt;
const PROMPT: &str = "Obnam passphrase: ";
@@ -13,11 +12,7 @@ pub struct Init {
}
impl Init {
- pub fn run(
- &self,
- config: &ClientConfigWithoutPasswords,
- config_filename: &Path,
- ) -> Result<(), ObnamError> {
+ pub fn run(&self, config: &ClientConfigWithoutPasswords) -> Result<(), ObnamError> {
if !config.encrypt {
panic!("no encryption specified");
}
@@ -28,7 +23,7 @@ impl Init {
};
let passwords = Passwords::new(&passphrase);
- let filename = passwords_filename(config_filename);
+ let filename = passwords_filename(&config.filename);
passwords
.save(&filename)
.map_err(|err| ObnamError::PasswordSave(filename, err))?;
diff --git a/src/config.rs b/src/config.rs
index 41ddcd6..d6ffbc5 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -52,6 +52,7 @@ impl ClientConfig {
#[derive(Debug, Serialize, Clone)]
pub struct ClientConfigWithoutPasswords {
+ pub filename: PathBuf,
pub server_url: String,
pub verify_tls_cert: bool,
pub chunk_size: usize,
@@ -92,6 +93,7 @@ impl ClientConfigWithoutPasswords {
let encrypt = tentative.encrypt.or(Some(false)).unwrap();
let config = Self {
+ filename: filename.to_path_buf(),
server_url: tentative.server_url,
roots: tentative.roots,
verify_tls_cert: tentative.verify_tls_cert.or(Some(false)).unwrap(),