Skip to content

Commit

Permalink
Program is the only public interface. (#574)
Browse files Browse the repository at this point in the history
  • Loading branch information
bolsinga authored Dec 31, 2024
1 parent 3b318a8 commit c0fe6cb
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 26 deletions.
2 changes: 1 addition & 1 deletion Sources/iTunes/Array+Codable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

extension Array where Element: Codable {
public func jsonData() throws -> Data {
func jsonData() throws -> Data {
let encoder = JSONEncoder()
encoder.outputFormatting = [.prettyPrinted, .sortedKeys]
encoder.dateEncodingStrategy = .iso8601
Expand Down
10 changes: 4 additions & 6 deletions Sources/iTunes/BackupCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ enum DestinationContext: EnumerableFlag {
extension SchemaConstraints: EnumerableFlag {}
extension Source: EnumerableFlag {}

public struct BackupCommand: AsyncParsableCommand {
public static let configuration = CommandConfiguration(
struct BackupCommand: AsyncParsableCommand {
static let configuration = CommandConfiguration(
commandName: "backup",
abstract: "Backs up music data.",
version: iTunesVersion
Expand Down Expand Up @@ -122,7 +122,7 @@ public struct BackupCommand: AsyncParsableCommand {
}

/// Validates the input matrix.
public func validate() throws {
func validate() throws {
if destination == .db && outputFile == nil {
throw ValidationError("--db requires outputDirectory to be set")
}
Expand All @@ -132,13 +132,11 @@ public struct BackupCommand: AsyncParsableCommand {
}
}

public func run() async throws {
func run() async throws {
let tracks = try await source.gather(reduce: reduce)

try await destination.context(outputFile: outputFile).emit(
tracks, branch: "main", tagPrefix: tagPrefix, version: Self.configuration.version,
schemaOptions: laxSchema.schemaOptions)
}

public init() {} // This is public and empty to help the compiler.
}
8 changes: 3 additions & 5 deletions Sources/iTunes/Batch/BatchCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import Foundation

extension Batch: EnumerableFlag {}

public struct BatchCommand: AsyncParsableCommand {
struct BatchCommand: AsyncParsableCommand {
private static let fileName = "itunes.json"

public static let configuration = CommandConfiguration(
static let configuration = CommandConfiguration(
commandName: "batch",
abstract: "Create many sql source or databases from a git repository.",
version: iTunesVersion
Expand Down Expand Up @@ -59,13 +59,11 @@ public struct BatchCommand: AsyncParsableCommand {
)
var outputDirectory: URL

public func run() async throws {
func run() async throws {
let configuration = GitTagData.Configuration(
directory: gitDirectory, tagPrefix: tagPrefix, fileName: Self.fileName)
try await batch.build(
configuration, outputDirectory: outputDirectory,
schemaOptions: laxSchema.schemaOptions)
}

public init() {} // This is public and empty to help the compiler.
}
2 changes: 1 addition & 1 deletion Sources/iTunes/Data+Utf8String.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

extension Data {
public func asUTF8String() throws -> String {
func asUTF8String() throws -> String {
enum DataUTF8Error: Error {
case cannotConvertToUTF8String
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/iTunes/GitTagData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ struct GitTagData {
let branch: String?
let fileName: String

public init(
init(
directory: URL, tagPrefix: String = "", branch: String? = nil, fileName: String
) {
self.directory = directory
Expand Down Expand Up @@ -118,7 +118,7 @@ struct GitTagData {

var index = 0

mutating public func next() async throws -> TagData? {
mutating func next() async throws -> TagData? {
guard !Task.isCancelled else { return nil }

guard index < tags.count else { return nil }
Expand Down
2 changes: 1 addition & 1 deletion Sources/iTunes/PackageBuildInfo+Version.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ extension PackageBuild {
}
}

public let iTunesVersion = PackageBuild.info.version
let iTunesVersion = PackageBuild.info.version
8 changes: 3 additions & 5 deletions Sources/iTunes/Patch/PatchCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import Foundation

extension Repairable: EnumerableFlag {}

public struct PatchCommand: AsyncParsableCommand {
struct PatchCommand: AsyncParsableCommand {
private static let fileName = "itunes.json"

public static let configuration = CommandConfiguration(
static let configuration = CommandConfiguration(
commandName: "patch",
abstract: "Creates patches for itunes.json data.",
version: iTunesVersion
Expand Down Expand Up @@ -36,11 +36,9 @@ public struct PatchCommand: AsyncParsableCommand {
@Option(help: "The corrections to apply when creating this patch (as a JSON string).")
var correction: String = ""

public func run() async throws {
func run() async throws {
let configuration = GitTagData.Configuration(
directory: gitDirectory, tagPrefix: sourceTagPrefix, fileName: PatchCommand.fileName)
print(try await repairable.gather(configuration, correction: correction))
}

public init() {} // This is public and empty to help the compiler.
}
8 changes: 3 additions & 5 deletions Sources/iTunes/Repair/RepairCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ extension Patchable {
}
}

public struct RepairCommand: AsyncParsableCommand {
struct RepairCommand: AsyncParsableCommand {
private static let fileName = "itunes.json"

public static let configuration = CommandConfiguration(
static let configuration = CommandConfiguration(
commandName: "repair",
abstract: "Repairs git repositories with itunes.json using a patch file.",
version: iTunesVersion
Expand Down Expand Up @@ -99,7 +99,7 @@ public struct RepairCommand: AsyncParsableCommand {
@Option(help: "The destination git branch. Defaults to the patchable type name.")
var destinationBranch: String?

public func run() async throws {
func run() async throws {
let patch = try patchable.createPatch(patchURL)

let sourceConfiguration = GitTagData.Configuration(
Expand All @@ -116,6 +116,4 @@ public struct RepairCommand: AsyncParsableCommand {
destinationTagPrefix: destinationTagPrefix,
destinationConfiguration: destinationConfiguration, version: Self.configuration.version)
}

public init() {} // This is public and empty to help the compiler.
}

0 comments on commit c0fe6cb

Please sign in to comment.