From efa8aa6e96ab7f303dad9c0312a89121a3933b88 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Sat, 15 Mar 2025 17:35:11 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20run-only=20=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E9=80=89=E9=A1=B9=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=B8=BB?= =?UTF-8?q?=E9=80=BB=E8=BE=91=E4=BB=A5=E6=94=AF=E6=8C=81=E4=BB=85=E8=BF=90?= =?UTF-8?q?=E8=A1=8C=E8=80=8C=E4=B8=8D=E5=A4=87=E4=BB=BD=E6=88=96=E6=81=A2?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 99bacc3..dcc78c6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -31,16 +31,18 @@ struct Main { _rclone_enable: bool, _skip_restore: bool, _backup_only: bool, + _run_only: bool, } impl Main { - fn new(cfg: cfg::Config, dryrun: bool, skip_restore: bool, backup_only: bool) -> Self { + fn new(cfg: cfg::Config, dryrun: bool, skip_restore: bool, backup_only: bool, run_only: bool) -> Self { Self { _rclone_enable: cfg.rclone_remote().is_some() && cfg.rclone_local().is_some(), _cfg: cfg, _dryrun: dryrun, _skip_restore: skip_restore, _backup_only: backup_only, + _run_only: run_only, } } @@ -182,18 +184,20 @@ impl Main { } fn run(&self) -> Result<(), Error> { - if !self._skip_restore && !self._backup_only { + if !self._run_only && !self._skip_restore && !self._backup_only { if self._rclone_enable { self.restore_rclone()?; } self.restore()?; } - if !self._backup_only { + if self._run_only || !self._backup_only { self.run_exe()?; } - self.backup()?; - if self._rclone_enable { - self.backup_rclone()?; + if !self._run_only { + self.backup()?; + if self._rclone_enable { + self.backup_rclone()?; + } } Ok(()) } @@ -247,6 +251,7 @@ fn main() -> ExitCode { opts.optflag("d", "dryrun", "Run without calling any process."); opts.optflag("r", "skip-restore", "Skip restore backup."); opts.optflag("b", "backup-only", "Backup only."); + opts.optflag("R", "run-only", "Run only. Do not backup or restore."); let result = match opts.parse(&argv[1..]) { Ok(m) => m, Err(err) => { @@ -279,6 +284,7 @@ fn main() -> ExitCode { result.opt_present("d"), result.opt_present("r"), result.opt_present("b"), + result.opt_present("R"), ); let e = match m.run() { Ok(_) => 0,