Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[platform] Remove SPM dependency #114

Merged
merged 46 commits into from
Apr 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
b034217
[platform] Update finch to latest package manifest version
namolnad Apr 13, 2019
9393c71
[platform] Only support swift 5
namolnad Apr 13, 2019
0eb9947
[platform] Update circle config for latest swift
namolnad Apr 13, 2019
99aaa69
[platform] Update circle config for latest xcode
namolnad Apr 13, 2019
4cc8c23
[platform] start to swap out routing library
namolnad Apr 13, 2019
7fe30f2
Remove dependency on BASIC
namolnad Apr 13, 2019
12c1fa7
Remove BASIC dependency from Shell
namolnad Apr 13, 2019
1f2afb4
Fix several compilation errors
namolnad Apr 13, 2019
38034c1
Allow other versions of swift
namolnad Apr 13, 2019
92f7c5a
Use package manifest for 5.0
namolnad Apr 13, 2019
3db134d
Move to micro library for Version type
namolnad Apr 13, 2019
c152e60
Cleanup imports due to public typealias
namolnad Apr 13, 2019
b43664b
WIP; building
namolnad Apr 14, 2019
609fdcd
Create VersionCommand; Use modes for config command; Fix Shell
namolnad Apr 14, 2019
090348f
Remove Version extension file. Guard against empty branchPrefix
namolnad Apr 14, 2019
c3e5415
Import version when update_version make target is run
namolnad Apr 14, 2019
c9dd449
Update invalid version resolver snapshot
namolnad Apr 14, 2019
477fd2b
Combine versions string for compare test
namolnad Apr 14, 2019
ee3621f
Update CompareCommand tests
namolnad Apr 14, 2019
1c17252
Update ChangeLogModelTests
namolnad Apr 14, 2019
7577373
Remove CommandRegistryTests
namolnad Apr 14, 2019
5be4468
Remove static linking stdlib option
namolnad Apr 14, 2019
aeb258e
Move AppError out of AppRunner
namolnad Apr 14, 2019
bb07e98
Merge branch 'dan_platform_update-spm-manifest-version' into dan_plat…
namolnad Apr 14, 2019
58ad5cd
[lint] Fix/ignore linting errors
namolnad Apr 15, 2019
f009512
[test] Remove SnapshotTestCase typealias
namolnad Apr 15, 2019
d002370
Update Yams version
namolnad Apr 15, 2019
ae18cb9
Update test dependencies
namolnad Apr 15, 2019
c17c3cd
Update Package.resolved for Quick swift 5 support
namolnad Apr 20, 2019
ec03448
Add package 4_2 file
namolnad Apr 20, 2019
d994381
Try going back to swift 4.2
namolnad Apr 20, 2019
b47268d
[platform] specify version 5 in 4.2 manifest
namolnad Apr 20, 2019
e48b3a4
[platform] Use conditional compilation for Process
namolnad Apr 20, 2019
58a108a
Add result type if before swift 5
namolnad Apr 20, 2019
1232e98
Typealias result for Swift < 5.0
namolnad Apr 20, 2019
2b1d483
Fix import swift directive
namolnad Apr 20, 2019
ae1be11
Less than not supported before swift 5
namolnad Apr 20, 2019
861a8b1
Import Result where needed
namolnad Apr 20, 2019
ad9cb91
Handle pre-swift 5 typealias for snapshot tests
namolnad Apr 20, 2019
b7acbbb
Revert importing of Result micro lib to use own result type
namolnad Apr 20, 2019
a0f3373
Make result enum public
namolnad Apr 20, 2019
3d95836
Revert creation of own Result type
namolnad Apr 20, 2019
fe80553
Try once more to use typealias
namolnad Apr 20, 2019
2012c61
Revert "Try once more to use typealias"
namolnad Apr 20, 2019
87f9276
Move Versions to own file
namolnad Apr 20, 2019
3275703
Use @_exported for Result type Swift < 5
namolnad Apr 20, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ executors:

mac:
macos:
xcode: "10.1.0"
xcode: "10.2.0"

go:
docker:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ APP_NAME_LOWERCASE=$(shell echo '$(APP_NAME)' | tr '[:upper:]' '[:lower:]')
APP_TMP=/tmp/$(APP_NAME).dst
BIN_DIR=$(INSTALL_DIR)/bin
BINARIES_DIR=/usr/local/bin
BUILD=swift build --static-swift-stdlib
BUILD=swift build
BUILD_NUMBER_FILE=./Sources/$(APP_NAME)/App/BuildNumber.swift
CONFIG_TEMPLATE=template.config.yml
CONFIRM=./Scripts/prompt_confirmation
Expand Down Expand Up @@ -123,7 +123,7 @@ ifdef NEW_VERSION
$(eval MAJOR:=$(word 1,$(VERSION_COMPONENTS)))
$(eval MINOR:=$(word 2,$(VERSION_COMPONENTS)))
$(eval PATCH:=$(word 3,$(VERSION_COMPONENTS)))
@echo "import struct Utility.Version\n\nlet appVersion: Version = .init($(MAJOR), $(MINOR), $(PATCH))" > $(VERSION_FILE)
@echo "import Version\n\nlet appVersion: Version = .init($(MAJOR), $(MINOR), $(PATCH))" > $(VERSION_FILE)
endif

xcodeproj:
Expand Down
48 changes: 42 additions & 6 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,57 @@
"object": {
"pins": [
{
"package": "SwiftPM",
"repositoryURL": "https://github.com/apple/swift-package-manager.git",
"package": "Commandant",
"repositoryURL": "https://github.com/Carthage/Commandant.git",
"state": {
"branch": null,
"revision": "235aacc514cb81a6881364b0fedcb3dd083228f3",
"version": "0.3.0"
"revision": "ab68611013dec67413628ac87c1f29e8427bc8e4",
"version": "0.17.0"
}
},
{
"package": "Curry",
"repositoryURL": "https://github.com/thoughtbot/Curry.git",
"state": {
"branch": null,
"revision": "4331dd50bc1db007db664a23f32e6f3df93d4e1a",
"version": "4.0.2"
}
},
{
"package": "Nimble",
"repositoryURL": "https://github.com/Quick/Nimble.git",
"state": {
"branch": null,
"revision": "43304bf2b1579fd555f2fdd51742771c1e4f2b98",
"version": "8.0.1"
}
},
{
"package": "Quick",
"repositoryURL": "https://github.com/Quick/Quick.git",
"state": {
"branch": null,
"revision": "94df9b449508344667e5afc7e80f8bcbff1e4c37",
"version": "2.1.0"
}
},
{
"package": "Version",
"repositoryURL": "https://github.com/mxcl/Version.git",
"state": {
"branch": null,
"revision": "61140c9f8a94c0326076fd2d44817834f4c6aafc",
"version": "1.1.0"
}
},
{
"package": "Yams",
"repositoryURL": "https://github.com/jpsim/Yams.git",
"state": {
"branch": null,
"revision": "b08dba4bcea978bf1ad37703a384097d3efce5af",
"version": "1.0.2"
"revision": "c947a306d2e80ecb2c0859047b35c73b8e1ca27f",
"version": "2.0.0"
}
}
]
Expand Down
27 changes: 19 additions & 8 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,40 @@

import PackageDescription

var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/Carthage/Commandant.git", from: "0.16.0"),
.package(url: "https://github.com/thoughtbot/Curry.git", from: "4.0.0"),
.package(url: "https://github.com/jpsim/Yams.git", from: "2.0.0"),
.package(url: "https://github.com/mxcl/Version.git", from: "1.0.0")
]

var finchDependencies: [Target.Dependency] = ["FinchCore", "Commandant", "Curry", "Version"]

#if swift(>=5.0)
dependencies.append(.package(url: "https://github.com/antitypical/Result.git", from:"4.1.0"))
finchDependencies.append("Result")
#endif

let package = Package(
name: "Finch",
products: [
.executable(name: "finch", targets: ["Finch"]),
.library(name: "FinchApp", targets: ["FinchApp"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-package-manager.git", from: "0.3.0"),
.package(url: "https://github.com/jpsim/Yams.git", from: "1.0.1"),
],
dependencies: dependencies,
targets: [
.target(
name: "Finch",
dependencies: ["FinchApp"]),
.target(
name: "FinchApp",
dependencies: ["FinchCore"]),
dependencies: finchDependencies),
.target(
name: "FinchCore",
dependencies: ["FinchUtilities"]),
.target(
name: "FinchUtilities",
dependencies: ["Utility", "Yams"]),
]
dependencies: ["Yams"])
],
swiftLanguageVersions: [.v4, .v4_2, .version("5")]
)

2 changes: 1 addition & 1 deletion Sources/Finch/App/Version.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import struct Utility.Version
import Version

let appVersion: Version = .init(0, 0, 23)
38 changes: 23 additions & 15 deletions Sources/FinchApp/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@
// Copyright © 2019 DHL. All rights reserved.
//

import struct Utility.Version
import Commandant
import struct FinchCore.Configuration
import FinchUtilities

/// :nodoc:
public typealias Version = Utility.Version
import Version

/// A structure to represent this app and its components.
public struct App {
Expand All @@ -35,19 +33,28 @@ public struct App {
}
}

/// App options received from the commandline.
struct Options {
/// Abstract base class of app options received from the commandline.
class Options {
enum Key: String {
case configPath = "config"
case projectDir = "project-dir"
case verbose = "verbose"
}

/// Path to config
var configPath: String?

/// The project directory if it is not the current working directory.
var projectDir: String?

/// Print the app version information and exit.
var shouldPrintVersion: Bool

/// Execute with verbose output.
var verbose: Bool

init(configPath: String?, projectDir: String?, verbose: Bool) {
self.configPath = configPath
self.projectDir = projectDir
self.verbose = verbose
}
}

/// The app's derived configuration.
Expand Down Expand Up @@ -78,10 +85,11 @@ public struct App {

/// :nodoc:
extension App.Options {
static let blank: App.Options = .init(
configPath: nil,
projectDir: nil,
shouldPrintVersion: false,
verbose: false
)
static var blank: App.Options {
return .init(
configPath: nil,
projectDir: nil,
verbose: false
)
}
}
92 changes: 39 additions & 53 deletions Sources/FinchApp/AppRunner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,63 @@
// Created by Dan Loman on 1/29/19.
//

import Commandant
import FinchUtilities
import enum Utility.ArgumentParserError
import Foundation

enum AppError: LocalizedError {
/// Unsupported mode (subcommand) for config command
case unsupportedConfigMode

/// Wraps error types which should be propogated
case wrapped(Error)

var localizedDescription: String {
switch self {
case .unsupportedConfigMode:
return Strings.Error.unsupportedConfigMode
case let .wrapped(error):
return error.localizedDescription
}

}
}

/**
* A class responsible for running the app. Internally registers
* all commands. Selects and runs the proper command.
*/
public class AppRunner {
private let environment: Environment

private let meta: App.Meta

private let output: OutputType

private let registry: CommandRegistry
private let registry: CommandRegistry<AppError> = .init()

/// :nodoc:
public init(environment: Environment, meta: App.Meta, output: OutputType = Output.instance) {
self.environment = environment
self.meta = meta
self.output = output
self.registry = .init(meta: meta)

registry.register {
CompareCommand(meta: meta, parser: $0).bindingGlobalOptions(to: $1)
}

registry.register {
ConfigCommand(meta: meta, parser: $0).bindingGlobalOptions(to: $1)
}
registry.register(CompareCommand(env: environment, meta: meta, output: output))
registry.register(ConfigCommand(env: environment, meta: meta, output: output))
registry.register(HelpCommand(registry: registry))
registry.register(VersionCommand(env: environment, meta: meta, output: output))
}

/// Runs the app with the included arguments.
public func run(arguments: [String]) {
do {
try _run(arguments: arguments)
} catch {
let message = (error as? ArgumentParserError)?.description ?? error.localizedDescription
// Drop argument for Finch executable
var args = arguments[1...]

let command = args.removeFirst()

guard let result = registry.run(command: command, arguments: Array(args)) else {
return
}

switch result {
case .success:
break
case .failure(let error):
let message = error.localizedDescription

output.print(
Strings.Error.formatted(errorMessage: message),
Expand All @@ -51,37 +70,4 @@ public class AppRunner {
)
}
}

private func _run(arguments: [String]) throws {
let args = Array(arguments.dropFirst())

let (command, options, result) = try registry.parse(arguments: args)

let config = Configurator(
options: options,
meta: meta,
environment: environment,
output: output
).configuration

let app: App = .init(
configuration: config,
meta: meta,
options: options,
output: output
)

if let command = command {
try registry.runCommand(
named: command,
with: result,
app: app,
env: environment
)
} else if options.shouldPrintVersion {
app.print("\(app.meta.name) \(app.meta.version) (\(app.meta.buildNumber))")
} else {
registry.printUsage()
}
}
}
49 changes: 30 additions & 19 deletions Sources/FinchApp/Command-Routing/Command.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,43 @@
// Created by Dan Loman on 1/29/19.
//

import Utility
import Commandant
import FinchUtilities
#if !swift(>=5.0)
@_exported import Result
#endif

/// :nodoc:
public typealias ParsingResult = ArgumentParser.Result

/// :nodoc:
///// :nodoc:
public typealias Environment = [String: String]

/// Protocol describing a command.
protocol Command {
/// Name of the command.
var name: String { get }
protocol Command: CommandProtocol where Options: App.Options {

var environment: Environment { get }

var meta: App.Meta { get }

/**
* Runs the command with the parsing result, app,
* and current environment.
*/
func run(with result: ParsingResult, app: App, env: Environment) throws
var output: OutputType { get }

/// Optional function to allow the command to bind to the main app options,
func bindingGlobalOptions(to binder: ArgumentBinder<App.Options>) -> Self
func run(options: Options, app: App, env: Environment) -> Result<(), ClientError>
}

/// :nodoc:
extension Command {
func bindingGlobalOptions(to binder: ArgumentBinder<App.Options>) -> Self {
return self
/// Should NOT be implemented by types conforming to Command.
func run(_ options: Options) -> Result<(), ClientError> {
let config = Configurator(
options: options,
meta: meta,
environment: environment,
output: output
).configuration

let app: App = .init(
configuration: config,
meta: meta,
options: options,
output: output
)

return run(options: options, app: app, env: environment)
}
}
Loading