mirror of
https://github.com/lifegpc/game-auto-sync.git
synced 2026-07-08 01:30:49 +08:00
添加 run-only 配置选项,修改主逻辑以支持仅运行而不备份或恢复
This commit is contained in:
18
src/main.rs
18
src/main.rs
@@ -31,16 +31,18 @@ struct Main {
|
|||||||
_rclone_enable: bool,
|
_rclone_enable: bool,
|
||||||
_skip_restore: bool,
|
_skip_restore: bool,
|
||||||
_backup_only: bool,
|
_backup_only: bool,
|
||||||
|
_run_only: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Main {
|
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 {
|
Self {
|
||||||
_rclone_enable: cfg.rclone_remote().is_some() && cfg.rclone_local().is_some(),
|
_rclone_enable: cfg.rclone_remote().is_some() && cfg.rclone_local().is_some(),
|
||||||
_cfg: cfg,
|
_cfg: cfg,
|
||||||
_dryrun: dryrun,
|
_dryrun: dryrun,
|
||||||
_skip_restore: skip_restore,
|
_skip_restore: skip_restore,
|
||||||
_backup_only: backup_only,
|
_backup_only: backup_only,
|
||||||
|
_run_only: run_only,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -182,18 +184,20 @@ impl Main {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn run(&self) -> Result<(), Error> {
|
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 {
|
if self._rclone_enable {
|
||||||
self.restore_rclone()?;
|
self.restore_rclone()?;
|
||||||
}
|
}
|
||||||
self.restore()?;
|
self.restore()?;
|
||||||
}
|
}
|
||||||
if !self._backup_only {
|
if self._run_only || !self._backup_only {
|
||||||
self.run_exe()?;
|
self.run_exe()?;
|
||||||
}
|
}
|
||||||
self.backup()?;
|
if !self._run_only {
|
||||||
if self._rclone_enable {
|
self.backup()?;
|
||||||
self.backup_rclone()?;
|
if self._rclone_enable {
|
||||||
|
self.backup_rclone()?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -247,6 +251,7 @@ fn main() -> ExitCode {
|
|||||||
opts.optflag("d", "dryrun", "Run without calling any process.");
|
opts.optflag("d", "dryrun", "Run without calling any process.");
|
||||||
opts.optflag("r", "skip-restore", "Skip restore backup.");
|
opts.optflag("r", "skip-restore", "Skip restore backup.");
|
||||||
opts.optflag("b", "backup-only", "Backup only.");
|
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..]) {
|
let result = match opts.parse(&argv[1..]) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
@@ -279,6 +284,7 @@ fn main() -> ExitCode {
|
|||||||
result.opt_present("d"),
|
result.opt_present("d"),
|
||||||
result.opt_present("r"),
|
result.opt_present("r"),
|
||||||
result.opt_present("b"),
|
result.opt_present("b"),
|
||||||
|
result.opt_present("R"),
|
||||||
);
|
);
|
||||||
let e = match m.run() {
|
let e = match m.run() {
|
||||||
Ok(_) => 0,
|
Ok(_) => 0,
|
||||||
|
|||||||
Reference in New Issue
Block a user