mirror of
https://github.com/Yuyi-Oak/BlueArchiveToolkit.git
synced 2026-07-22 07:06:43 +08:00
feat: add official sync startup banner
This commit is contained in:
@@ -13,6 +13,18 @@ const EXIT_ERROR: i32 = 1;
|
||||
const EXIT_LOCKED: i32 = 75;
|
||||
const DEFAULT_WATCH_INTERVAL_SECONDS: u64 = 60 * 60;
|
||||
const DEFAULT_ERROR_RETRY_SECONDS: u64 = 60;
|
||||
const STARTUP_BANNER: &str = r#"
|
||||
============================================================
|
||||
____ _ _ _ _ _____ _ _ _ _
|
||||
| __ )| |_ _ ___ / \ _ __ ___| |__ (_)_ _____|_ _|__ ___ | | | _(_) |_
|
||||
| _ \| | | | |/ _ \/ _ \ | '__/ __| '_ \| \ \ / / _ \ | |/ _ \ / _ \| | |/ / | __|
|
||||
| |_) | | |_| | __/ ___ \| | | (__| | | | |\ V / __/ | | (_) | (_) | | <| | |_
|
||||
|____/|_|\__,_|\___/_/ \_\_| \___|_| |_|_| \_/ \___| |_|\___/ \___/|_|_|\_\_|\__|
|
||||
|
||||
BlueArchiveToolkit
|
||||
Official Resource Sync
|
||||
============================================================
|
||||
"#;
|
||||
|
||||
fn main() {
|
||||
match run() {
|
||||
@@ -41,6 +53,9 @@ fn main() {
|
||||
|
||||
fn run() -> anyhow::Result<()> {
|
||||
let options = parse_args()?;
|
||||
if options.banner {
|
||||
print_startup_banner();
|
||||
}
|
||||
if options.watch {
|
||||
run_watch(options)?;
|
||||
} else {
|
||||
@@ -73,6 +88,7 @@ struct CliOptions {
|
||||
quiet_up_to_date: bool,
|
||||
quiet_up_to_date_explicit: bool,
|
||||
progress: bool,
|
||||
banner: bool,
|
||||
}
|
||||
|
||||
impl Default for CliOptions {
|
||||
@@ -85,6 +101,7 @@ impl Default for CliOptions {
|
||||
quiet_up_to_date: false,
|
||||
quiet_up_to_date_explicit: false,
|
||||
progress: true,
|
||||
banner: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -175,6 +192,10 @@ impl ProgressLogger {
|
||||
}
|
||||
}
|
||||
|
||||
fn print_startup_banner() {
|
||||
eprintln!("{STARTUP_BANNER}");
|
||||
}
|
||||
|
||||
fn should_print_status(status: OfficialUpdateStatus, quiet_up_to_date: bool) -> bool {
|
||||
!(quiet_up_to_date && status == OfficialUpdateStatus::UpToDate)
|
||||
}
|
||||
@@ -290,9 +311,17 @@ fn parse_args_from(raw_args: impl IntoIterator<Item = String>) -> anyhow::Result
|
||||
}
|
||||
"--progress" => {
|
||||
options.progress = true;
|
||||
options.banner = true;
|
||||
}
|
||||
"--no-progress" => {
|
||||
options.progress = false;
|
||||
options.banner = false;
|
||||
}
|
||||
"--banner" => {
|
||||
options.banner = true;
|
||||
}
|
||||
"--no-banner" => {
|
||||
options.banner = false;
|
||||
}
|
||||
"--help" | "-h" => {
|
||||
print_usage(&binary);
|
||||
@@ -334,7 +363,7 @@ fn print_usage(binary: &str) {
|
||||
[--app-version 1.70.0] [--connection-group <name>] [--launcher-version 1.7.2] \
|
||||
[--platforms Windows,Android] [--output official_update_output] [--snapshot official-sync-snapshot.json] \
|
||||
[--curl curl] [--unzip unzip] [--dry-run] [--plan] [--force] [--audit-local|--no-audit-local] [--repair|--no-repair] \
|
||||
[--watch] [--interval 1h|60m|3600s] [--error-retry 60s] [--quiet-up-to-date|--no-quiet-up-to-date] [--progress|--no-progress]"
|
||||
[--watch] [--interval 1h|60m|3600s] [--error-retry 60s] [--quiet-up-to-date|--no-quiet-up-to-date] [--progress|--no-progress] [--banner|--no-banner]"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -438,6 +467,7 @@ mod tests {
|
||||
assert!(!options.quiet_up_to_date);
|
||||
assert!(!options.quiet_up_to_date_explicit);
|
||||
assert!(options.progress);
|
||||
assert!(options.banner);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -520,12 +550,31 @@ mod tests {
|
||||
fn parses_progress_flags() {
|
||||
let options = parse(&["bat-official-sync"]).unwrap();
|
||||
assert!(options.progress);
|
||||
assert!(options.banner);
|
||||
|
||||
let options = parse(&["bat-official-sync", "--no-progress"]).unwrap();
|
||||
assert!(!options.progress);
|
||||
assert!(!options.banner);
|
||||
|
||||
let options = parse(&["bat-official-sync", "--no-progress", "--progress"]).unwrap();
|
||||
assert!(options.progress);
|
||||
assert!(options.banner);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parses_banner_flags() {
|
||||
let options = parse(&["bat-official-sync", "--no-banner"]).unwrap();
|
||||
assert!(options.progress);
|
||||
assert!(!options.banner);
|
||||
|
||||
let options = parse(&["bat-official-sync", "--no-progress", "--banner"]).unwrap();
|
||||
assert!(!options.progress);
|
||||
assert!(options.banner);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn startup_banner_contains_product_name() {
|
||||
assert!(STARTUP_BANNER.contains("BlueArchiveToolkit"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user