Skip to content

Commit 0296eec

Browse files
committed
feat: add dropbox token arg
1 parent e34e8a2 commit 0296eec

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/backup.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use anyhow::Result;
22

3+
/// Perform a backup of the folder, uploading it to Dropbox once complete.
34
pub fn backup() -> Result<()> {
45
Ok(())
56
}

src/config.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ struct Cli {
2020
/// If not specified, the backup will only run once
2121
#[arg(short, long, value_name = "CRON")]
2222
schedule: Option<String>,
23+
24+
/// A Dropbox access token
25+
#[arg(short = 't', long = "token", value_name = "KEY")]
26+
dropbox_token: Option<String>,
2327
}
2428

2529
/// Runtime parameters, parsed and ready to be used
@@ -28,6 +32,8 @@ pub struct Params {
2832
pub folder: PathBuf,
2933
/// An optional parsed cron expression
3034
pub schedule: Option<Schedule>,
35+
/// A Dropbox access token
36+
pub dropbox_token: String,
3137
}
3238

3339
/// Parse the command-line arguments and environment variables into runtime params
@@ -43,6 +49,10 @@ pub fn parse_config() -> Result<Params> {
4349
.schedule
4450
.or_else(|| env::var("DOCKERBOX_SCHEDULE").ok());
4551

52+
params.dropbox_token = params
53+
.dropbox_token
54+
.or_else(|| env::var("DOCKERBOX_TOKEN").ok());
55+
4656
let folder = params.folder.or_panic(); // Ok to unwrap due to default value
4757
let folder = folder
4858
.canonicalize()
@@ -59,5 +69,13 @@ pub fn parse_config() -> Result<Params> {
5969
None => None,
6070
};
6171

62-
Ok(Params { folder, schedule })
72+
let Some(dropbox_token) = params.dropbox_token else {
73+
return Err(anyhow!("No Dropbox token was provided"));
74+
};
75+
76+
Ok(Params {
77+
folder,
78+
schedule,
79+
dropbox_token,
80+
})
6381
}

0 commit comments

Comments
 (0)