Scaffold v1.0.0
This commit is contained in:
29
Sources/EmbedderTool/CommandLineInvocation.swift
Normal file
29
Sources/EmbedderTool/CommandLineInvocation.swift
Normal file
@@ -0,0 +1,29 @@
|
||||
import Foundation
|
||||
|
||||
struct CommandLineInvocation {
|
||||
let sourceDirectory: URL
|
||||
let outputFile: URL
|
||||
}
|
||||
|
||||
extension CommandLineInvocation {
|
||||
static func parse(_ arguments: [String]) throws -> CommandLineInvocation {
|
||||
guard arguments.count == 3 else {
|
||||
throw CommandLineInvocationError.wrongNumberOfArguments(received: arguments.count - 1)
|
||||
}
|
||||
return CommandLineInvocation(
|
||||
sourceDirectory: URL(fileURLWithPath: arguments[1]),
|
||||
outputFile: URL(fileURLWithPath: arguments[2])
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
enum CommandLineInvocationError: Error, CustomStringConvertible {
|
||||
case wrongNumberOfArguments(received: Int)
|
||||
|
||||
var description: String {
|
||||
switch self {
|
||||
case .wrongNumberOfArguments(let received):
|
||||
return "expected 2 arguments (source directory, output file); received \(received)"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user