Skip to content

Commit

Permalink
Adopting async parsable
Browse files Browse the repository at this point in the history
  • Loading branch information
samdeane committed Aug 29, 2024
1 parent 2c208f7 commit 5ef86f4
Show file tree
Hide file tree
Showing 22 changed files with 185 additions and 52 deletions.
6 changes: 3 additions & 3 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "1d516274e2bc44fe8a00c65a502324ec27ff11269ac861ce34769a0c96b78a76",
"originHash" : "c2dd8b3a13b22626bdf54e0714df7abbae080ce71991455d881c1092898abf6d",
"pins" : [
{
"identity" : "coercion",
Expand Down Expand Up @@ -42,8 +42,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/apple/swift-argument-parser",
"state" : {
"revision" : "6b2aa2748a7881eebb9f84fb10c01293e15b52ca",
"version" : "0.5.0"
"revision" : "41982a3656a71c768319979febd796c6fd111d5c",
"version" : "1.5.0"
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let package = Package(
.package(url: "https://github.com/elegantchaos/Runner.git", from: "2.0.5"),
.package(url: "https://github.com/elegantchaos/XCTestExtensions.git", from: "1.3.0"),
.package(url: "https://github.com/elegantchaos/Versionator.git", from: "2.0.2"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "0.5.0"),
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.5.0"),
],

targets: [
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/ArchiveCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// All code (c) 2019 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation

import protocol ArgumentParser.AsyncParsableCommand

struct WorkspaceSpec: Decodable {
let name: String
let schemes: [String]
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/BootstrapCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// All code (c) 2021 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Files
import Foundation
import Resources

import protocol ArgumentParser.AsyncParsableCommand

struct BootstrapCommand: AsyncParsableCommand {
enum Error: Swift.Error {
case couldntCopyConfigs(error: Swift.Error)
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/ChangesCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import AppKit
import ArgumentParser
import Foundation

import protocol ArgumentParser.AsyncParsableCommand

enum ChangesError: Error {
case couldntFetchLog(error: Error)

Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/CompressCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// All code (c) 2019 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation
import Runner

import protocol ArgumentParser.AsyncParsableCommand

enum CompressError: Error {
case compressFailed(_ output: String)

Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/ExportCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// All code (c) 2019 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation

import protocol ArgumentParser.AsyncParsableCommand

enum ExportError: Error {
case exportFailed(_ output: String)
case writingOptionsFailed(_ output: Error)
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/GetCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// All code (c) 2020 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation

import protocol ArgumentParser.AsyncParsableCommand

struct GetCommand: AsyncParsableCommand {
static var configuration: CommandConfiguration {
CommandConfiguration(
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/InstallCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// All code (c) 2019 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation

import protocol ArgumentParser.AsyncParsableCommand

enum InstallError: Error {
case couldntWriteStub

Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/NotarizeCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// All code (c) 2020 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation
import Runner

import protocol ArgumentParser.AsyncParsableCommand

enum NotarizeError: Error, Sendable {
case compressingFailed(_ result: Runner.RunningProcess)
case notarizingFailed(
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/PublishCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// All code (c) 2019 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation
import Runner

import protocol ArgumentParser.AsyncParsableCommand

enum PublishError: Error {
case commitFailed(_ result: Runner.RunningProcess)
case pushFailed(_ result: Runner.RunningProcess)
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/SetCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// All code (c) 2020 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation

import protocol ArgumentParser.AsyncParsableCommand

struct SetCommand: AsyncParsableCommand {
static var configuration: CommandConfiguration {
CommandConfiguration(
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/SubmitCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// All code (c) 2022 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation
import Runner

import protocol ArgumentParser.AsyncParsableCommand

/// Performs the following commands in order:
/// - archive
/// - export
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/UnsetCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
// All code (c) 2020 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation

import protocol ArgumentParser.AsyncParsableCommand

struct UnsetCommand: AsyncParsableCommand {
static var configuration: CommandConfiguration {
CommandConfiguration(
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/UpdateBuildCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// All code (c) 2019 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Files
import Foundation
import Resources
import Runner

import protocol ArgumentParser.AsyncParsableCommand

enum UpdateBuildError: Error {
case gettingBuildFailed(_ result: Runner.RunningProcess)
case gettingCommitFailed(_ result: Runner.RunningProcess)
Expand Down
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/Commands/UploadCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
// All code (c) 2020 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Foundation
import Runner

import protocol ArgumentParser.AsyncParsableCommand

enum UploadError: Error {
case uploadingFailed(_ result: Runner.RunningProcess)
case savingUploadReceiptFailed(_ error: Error)
Expand Down
18 changes: 18 additions & 0 deletions Sources/ReleaseTools/Data+AsyncSequence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import Foundation

extension Data {
/// Initialise a data buffer from an async sequence of UInt8.
/// Consumes the entire sequence.
public init<T: AsyncSequence>(_ sequence: T) async where T.Element == UInt8 {
var data = Data()
do {
for try await byte in sequence {
data.append(byte)
}
} catch {

}

self = data
}
}
3 changes: 2 additions & 1 deletion Sources/ReleaseTools/OptionParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// All code (c) 2020 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import ArgumentParser
import Files
import Foundation
import Runner

import protocol ArgumentParser.AsyncParsableCommand

enum GeneralError: Error, CustomStringConvertible, Sendable {
case infoUnreadable(_ path: String)
case missingWorkspace
Expand Down
77 changes: 77 additions & 0 deletions Sources/ReleaseTools/RootCommand.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
// Created by Sam Deane on 11/10/2018.
// All code (c) 2018 - present day, Elegant Chaos Limited.
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-

import Foundation
import Logger
import Runner

import protocol ArgumentParser.AsyncMain
import protocol ArgumentParser.AsyncParsableCommand

// class Shell {
// var semaphore: DispatchSemaphore? = nil
// var error: Error? = nil
// var showOutput: Bool = false

// func log(_ message: String) {
// print(message)
// }

// }

// let sharedShell = Shell()

@main
struct Main: AsyncMain {
typealias Command = RootCommand
}

struct RootCommand: AsyncParsableCommand {
static var configuration: CommandConfiguration {
CommandConfiguration(
abstract: "Assorted tools for iOS/macOS releases.",
subcommands: [
AppcastCommand.self,
ArchiveCommand.self,
BootstrapCommand.self,
ChangesCommand.self,
CompressCommand.self,
ExportCommand.self,
GetCommand.self,
InstallCommand.self,
NotarizeCommand.self,
PublishCommand.self,
SetCommand.self,
SubmitCommand.self,
UnsetCommand.self,
UpdateBuildCommand.self,
UploadCommand.self,
WaitForNotarizationCommand.self,
],
defaultSubcommand: nil
)
}

@Flag(help: "Show the version.") var version = false

mutating func run() async throws {
if version {
print(VersionatorVersion.git)
} else {
throw CleanExit.helpRequest(self)
}
Logger.defaultManager.flush()
}
}

// do {
// var command = try Command.parseAsRoot()
// try command.run()
// Logger.defaultManager.flush()
// Command.exit()
// } catch {
// Logger.defaultManager.flush()
// Command.exit(withError: error)
// }
13 changes: 13 additions & 0 deletions Sources/ReleaseTools/RunnerExtras.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Runner

// TODO: move into Runner
extension Runner.RunningProcess {
/// Check the state of the process and throw an error if it failed.
func throwIfFailed(_ e: @autoclosure () async -> Error) async throws {
for await state in self.state {
if state != .succeeded {
throw await e()
}
}
}
}
Loading

0 comments on commit 5ef86f4

Please sign in to comment.