Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the password args/envvars optional #56

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::restic::Password;
#[derive(Debug)]
pub struct Args {
pub repository: Repository,
pub password: Password,
pub password: Option<Password>,
pub parallelism: usize,
pub log_level: LevelFilter,
pub no_cache: bool,
Expand All @@ -27,11 +27,11 @@ impl Args {
unreachable!("Error in Config: neither repo nor repository_file found. Please open an issue if you see this.")
},
password: if let Some(command) = cli.password_command {
Password::Command(command)
Some(Password::Command(command))
} else if let Some(file) = cli.password_file {
Password::File(file)
Some(Password::File(file))
} else {
unreachable!("Error in Config: neither password_command nor password_file found. Please open an issue if you see this.")
None
},
parallelism: cli.parallelism,
log_level: match cli.verbose {
Expand Down Expand Up @@ -83,7 +83,6 @@ impl Args {
))]
#[command(group(
ArgGroup::new("password")
.required(true)
.args(["password_command", "password_file"]),
))]
struct Cli {
Expand Down
14 changes: 9 additions & 5 deletions src/restic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub struct Config {

pub struct Restic {
repository: Repository,
password: Password,
password: Option<Password>,
no_cache: bool,
}

Expand All @@ -119,7 +119,7 @@ pub enum Password {
impl Restic {
pub fn new(
repository: Repository,
password: Password,
password: Option<Password>,
no_cache: bool,
) -> Self {
Restic { repository, password, no_cache }
Expand Down Expand Up @@ -213,9 +213,13 @@ impl Restic {
Repository::File(file) => cmd.arg("--repository-file").arg(file),
};
match &self.password {
Password::Command(command) =>
cmd.arg("--password-command").arg(command),
Password::File(file) => cmd.arg("--password-file").arg(file),
Some(Password::Command(command)) => {
cmd.arg("--password-command").arg(command);
}
Some(Password::File(file)) => {
cmd.arg("--password-file").arg(file);
}
None => {}
};
if self.no_cache {
cmd.arg("--no-cache");
Expand Down