Skip to content

Commit

Permalink
site_tool uses VaultModel (#622)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolsinga authored Sep 14, 2023
1 parent 962fe51 commit 93c1d6b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
4 changes: 2 additions & 2 deletions Sources/Site/Music/VaultModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ extension VaultError: LocalizedError {
@MainActor public final class VaultModel: ObservableObject {
let urlString: String

@Published var vault: Vault?
@Published public var vault: Vault?
@Published var error: Error?
@Published var todayConcerts: [Concert] = []
@Published var venuePlacemarks: [Venue.ID: CLPlacemark] = [:]
Expand All @@ -41,7 +41,7 @@ extension VaultError: LocalizedError {
self.error = error
}

func load() async {
public func load() async {
Logger.vaultModel.log("start")
defer {
Logger.vaultModel.log("end")
Expand Down
9 changes: 6 additions & 3 deletions Sources/site_tool/Program.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import Site

@main
struct Program: AsyncParsableCommand {
enum URLError: Error {
enum ProgramError: Error {
case notURLString(String)
case noVault
}

@Argument(
help:
"The root URL for the json files.",
transform: ({
let url = URL(string: $0)
guard let url else { throw URLError.notURLString($0) }
guard let url else { throw ProgramError.notURLString($0) }
return url
})
)
Expand All @@ -46,7 +47,9 @@ struct Program: AsyncParsableCommand {

try jsonDirectoryURL?.appending(path: "diary.json").writeJSON(diary)

let vault = try await Vault.load(url: rootURL.appending(path: "music.json"))
let model = await VaultModel(urlString: rootURL.appending(path: "music.json").absoluteString)
await model.load()
guard let vault = await model.vault else { throw ProgramError.noVault }

let concerts = vault.concerts
let artistDigests = vault.artistDigests
Expand Down

0 comments on commit 93c1d6b

Please sign in to comment.