Merge pull request #5 from alexwlchan/add-version
- ID
8642ea3- date
2024-05-17 06:37:08+00:00- author
Alex Chan <alex@alexwlchan.net>- parents
4897da2,bbf6451- message
Merge pull request #5 from alexwlchan/add-version Add a flag to print the version number- changed files
2 files, 19 additions
Changed files
save_safari_webarchive.swift (3490) → save_safari_webarchive.swift (3727)
diff --git a/save_safari_webarchive.swift b/save_safari_webarchive.swift
index a0dff0a..dcbbc20 100755
--- a/save_safari_webarchive.swift
+++ b/save_safari_webarchive.swift
@@ -19,6 +19,8 @@
import WebKit
+let SCRIPT_VERSION = "1.0"
+
/// Print an error message and terminate the process if there are
/// any errors while loading a page.
class ExitOnFailureDelegate: NSObject, WKNavigationDelegate {
@@ -111,6 +113,12 @@ extension WKWebView {
}
}
+if CommandLine.arguments.count == 2 && CommandLine.arguments[1] == "--version" {
+ let filename = (CommandLine.arguments[0] as NSString).lastPathComponent
+ print("\(filename) \(SCRIPT_VERSION)")
+ exit(0)
+}
+
guard CommandLine.arguments.count == 3 else {
fputs("Usage: \(CommandLine.arguments[0]) <URL> <OUTPUT_PATH>\n", stderr)
exit(1)
tests/test_save_safari_webarchive.py (3764) → tests/test_save_safari_webarchive.py (4044)
diff --git a/tests/test_save_safari_webarchive.py b/tests/test_save_safari_webarchive.py
index 4e0a8fe..03e9e94 100755
--- a/tests/test_save_safari_webarchive.py
+++ b/tests/test_save_safari_webarchive.py
@@ -3,6 +3,7 @@
import os
import pathlib
import plistlib
+import re
import pytest
@@ -129,3 +130,13 @@ def test_it_fails_if_url_is_invalid(out_path: pathlib.Path) -> None:
}
assert not out_path.exists()
+
+
+def test_prints_the_version() -> None:
+ result = save_safari_webarchive(["--version"])
+
+ assert result["returncode"] == 0
+ assert result["stderr"] is None
+ assert re.match(
+ r"^save_safari_webarchive.swift [0-9]+\.[0-9]+\n$", result["stdout"]
+ )