Add skeleton for verbosity
This commit is contained in:
parent
4e15f26823
commit
6124c3e6d1
|
@ -29,7 +29,8 @@ struct CommandLineOptions {
|
||||||
struct NoCommandError: Swift.Error { }
|
struct NoCommandError: Swift.Error { }
|
||||||
|
|
||||||
private let parser: ArgumentParser
|
private let parser: ArgumentParser
|
||||||
private(set) var subCommand: SubCommand
|
fileprivate(set) var subCommand: SubCommand
|
||||||
|
fileprivate(set) var verbosity: Verbosity
|
||||||
|
|
||||||
private static let allCommands: [Command] = [
|
private static let allCommands: [Command] = [
|
||||||
ListDevicesCommand(),
|
ListDevicesCommand(),
|
||||||
|
@ -47,16 +48,7 @@ struct CommandLineOptions {
|
||||||
)
|
)
|
||||||
|
|
||||||
let binder = ArgumentBinder<CommandLineOptions>()
|
let binder = ArgumentBinder<CommandLineOptions>()
|
||||||
|
binder.bind(parser)
|
||||||
binder.bind(
|
|
||||||
option: parser.add(
|
|
||||||
option: "--version",
|
|
||||||
kind: Bool.self,
|
|
||||||
usage: "Prints the version and exits"
|
|
||||||
), to: { options, _ in
|
|
||||||
options.subCommand = .version
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
for command in allCommands {
|
for command in allCommands {
|
||||||
let subparser = parser.add(
|
let subparser = parser.add(
|
||||||
|
@ -66,7 +58,7 @@ struct CommandLineOptions {
|
||||||
command.addOptions(to: subparser)
|
command.addOptions(to: subparser)
|
||||||
}
|
}
|
||||||
|
|
||||||
var options = CommandLineOptions(parser: parser, subCommand: .noCommand)
|
var options = CommandLineOptions(parser: parser, subCommand: .noCommand, verbosity: .normal)
|
||||||
checkresult: do {
|
checkresult: do {
|
||||||
let result = try parser.parse(arguments)
|
let result = try parser.parse(arguments)
|
||||||
try binder.fill(parseResult: result, into: &options)
|
try binder.fill(parseResult: result, into: &options)
|
||||||
|
@ -98,3 +90,28 @@ struct CommandLineOptions {
|
||||||
parser.printUsage(on: stream)
|
parser.printUsage(on: stream)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extension ArgumentBinder where Options == CommandLineOptions {
|
||||||
|
func bind(_ parser: ArgumentParser) {
|
||||||
|
bind(
|
||||||
|
option: parser.add(
|
||||||
|
option: "--version",
|
||||||
|
kind: Bool.self,
|
||||||
|
usage: "Prints the version and exits"
|
||||||
|
), to: { options, _ in
|
||||||
|
options.subCommand = .version
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
bind(
|
||||||
|
option: parser.add(
|
||||||
|
option: "--verbosity",
|
||||||
|
kind: Verbosity.self,
|
||||||
|
usage: "Verbosity: silent|normal|loud, defaults to normal"
|
||||||
|
), to: { options, verbosity in
|
||||||
|
options.verbosity = verbosity
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ struct FilteringOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
extension ArgumentBinder where Options == FilteringOptions {
|
extension ArgumentBinder where Options == FilteringOptions {
|
||||||
func bind(to options: inout FilteringOptions, parser: ArgumentParser) {
|
func bind(_ parser: ArgumentParser) {
|
||||||
bind(option: parser.add(
|
bind(option: parser.add(
|
||||||
option: "--availability",
|
option: "--availability",
|
||||||
kind: FilteringOptions.Availability.self,
|
kind: FilteringOptions.Availability.self,
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
//
|
||||||
|
// Copyright © 2019 Simon Kågedal Reimer. See LICENSE.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
import SPMUtility
|
||||||
|
|
||||||
|
enum Verbosity: String, StringEnumArgument {
|
||||||
|
case silent
|
||||||
|
case normal
|
||||||
|
case loud
|
||||||
|
|
||||||
|
public static var completion: ShellCompletion = .none
|
||||||
|
}
|
|
@ -14,5 +14,5 @@ protocol Command {
|
||||||
|
|
||||||
func addOptions(to parser: ArgumentParser)
|
func addOptions(to parser: ArgumentParser)
|
||||||
func fillParseResult(_ parseResult: ArgumentParser.Result) throws
|
func fillParseResult(_ parseResult: ArgumentParser.Result) throws
|
||||||
func run() throws
|
func run(reporter: Reporter) throws
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ class ExportCACommand: Command {
|
||||||
private var exportedCertificates: Set<Data> = []
|
private var exportedCertificates: Set<Data> = []
|
||||||
|
|
||||||
func addOptions(to parser: ArgumentParser) {
|
func addOptions(to parser: ArgumentParser) {
|
||||||
filteringBinder.bind(to: &filteringOptions, parser: parser)
|
filteringBinder.bind(parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillParseResult(_ parseResult: ArgumentParser.Result) throws {
|
func fillParseResult(_ parseResult: ArgumentParser.Result) throws {
|
||||||
|
@ -29,7 +29,7 @@ class ExportCACommand: Command {
|
||||||
try filteringBinder.fill(parseResult: parseResult, into: &filteringOptions)
|
try filteringBinder.fill(parseResult: parseResult, into: &filteringOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() throws {
|
func run(reporter: Reporter) throws {
|
||||||
exportedCertificates = []
|
exportedCertificates = []
|
||||||
for device in try Simctl.flatListDevices().filter(using: filteringOptions) {
|
for device in try Simctl.flatListDevices().filter(using: filteringOptions) {
|
||||||
exportCertificates(for: device)
|
exportCertificates(for: device)
|
||||||
|
|
|
@ -36,7 +36,7 @@ class InstallCACommand: Command {
|
||||||
options.path = path
|
options.path = path
|
||||||
})
|
})
|
||||||
|
|
||||||
filteringBinder.bind(to: &filteringOptions, parser: parser)
|
filteringBinder.bind(parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillParseResult(_ parseResult: ArgumentParser.Result) throws {
|
func fillParseResult(_ parseResult: ArgumentParser.Result) throws {
|
||||||
|
@ -44,7 +44,7 @@ class InstallCACommand: Command {
|
||||||
try filteringBinder.fill(parseResult: parseResult, into: &filteringOptions)
|
try filteringBinder.fill(parseResult: parseResult, into: &filteringOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() throws {
|
func run(reporter: Reporter) throws {
|
||||||
let url = URL(fileURLWithPath: options.path!)
|
let url = URL(fileURLWithPath: options.path!)
|
||||||
let certificate = try Certificate.load(from: url)
|
let certificate = try Certificate.load(from: url)
|
||||||
let sha1 = certificate.sha1
|
let sha1 = certificate.sha1
|
||||||
|
|
|
@ -14,15 +14,14 @@ class ListDevicesCommand: Command {
|
||||||
private let filteringBinder = ArgumentBinder<FilteringOptions>()
|
private let filteringBinder = ArgumentBinder<FilteringOptions>()
|
||||||
|
|
||||||
func addOptions(to parser: ArgumentParser) {
|
func addOptions(to parser: ArgumentParser) {
|
||||||
filteringBinder.bind(to: &filteringOptions, parser: parser)
|
filteringBinder.bind(parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillParseResult(_ parseResult: ArgumentParser.Result) throws {
|
func fillParseResult(_ parseResult: ArgumentParser.Result) throws {
|
||||||
try filteringBinder.fill(parseResult: parseResult, into: &filteringOptions)
|
try filteringBinder.fill(parseResult: parseResult, into: &filteringOptions)
|
||||||
// try binder.fill(parseResult: parseResult, into: &self)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() throws {
|
func run(reporter: Reporter) throws {
|
||||||
let allDevices = try Simctl.listDevices()
|
let allDevices = try Simctl.listDevices()
|
||||||
for (runtime, devices) in allDevices.devices {
|
for (runtime, devices) in allDevices.devices {
|
||||||
let filteredDevices = devices.filter(using: filteringOptions)
|
let filteredDevices = devices.filter(using: filteringOptions)
|
||||||
|
|
|
@ -27,7 +27,7 @@ class RemoveCACommand: Command {
|
||||||
options.dryRun = dryRun
|
options.dryRun = dryRun
|
||||||
})
|
})
|
||||||
|
|
||||||
filteringBinder.bind(to: &filteringOptions, parser: parser)
|
filteringBinder.bind(parser)
|
||||||
}
|
}
|
||||||
|
|
||||||
func fillParseResult(_ parseResult: ArgumentParser.Result) throws {
|
func fillParseResult(_ parseResult: ArgumentParser.Result) throws {
|
||||||
|
@ -35,7 +35,7 @@ class RemoveCACommand: Command {
|
||||||
try filteringBinder.fill(parseResult: parseResult, into: &filteringOptions)
|
try filteringBinder.fill(parseResult: parseResult, into: &filteringOptions)
|
||||||
}
|
}
|
||||||
|
|
||||||
func run() throws {
|
func run(reporter: Reporter) throws {
|
||||||
for device in try Simctl.flatListDevices().filter(using: filteringOptions) {
|
for device in try Simctl.flatListDevices().filter(using: filteringOptions) {
|
||||||
let trustStore = TrustStore(uuid: device.udid)
|
let trustStore = TrustStore(uuid: device.udid)
|
||||||
if trustStore.exists {
|
if trustStore.exists {
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
//
|
||||||
|
// Copyright © 2019 Simon Kågedal Reimer. See LICENSE.
|
||||||
|
//
|
||||||
|
|
||||||
|
import Foundation
|
||||||
|
|
||||||
|
protocol Reporter {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class DefaultReporter: Reporter {
|
||||||
|
private let verbosity: Verbosity
|
||||||
|
|
||||||
|
init(verbosity: Verbosity) {
|
||||||
|
self.verbosity = verbosity
|
||||||
|
}
|
||||||
|
}
|
|
@ -41,7 +41,7 @@ public class XcodeSimulatorTool {
|
||||||
case .version:
|
case .version:
|
||||||
print("xcode-simulator-tool version \(XcodeSimulatorTool.version)")
|
print("xcode-simulator-tool version \(XcodeSimulatorTool.version)")
|
||||||
case .command(let command):
|
case .command(let command):
|
||||||
try command.run()
|
try command.run(reporter: DefaultReporter(verbosity: options.verbosity))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue