Skip to content

Commit

Permalink
Merge pull request #5 from alexwlchan/add-version
Browse files Browse the repository at this point in the history
Add a flag to print the version number
  • Loading branch information
alexwlchan authored May 17, 2024
2 parents 4897da2 + bbf6451 commit 8642ea3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions save_safari_webarchive.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions tests/test_save_safari_webarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import pathlib
import plistlib
import re

import pytest

Expand Down Expand Up @@ -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"]
)

0 comments on commit 8642ea3

Please sign in to comment.