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

Create seperate BeakCLI target #31

Merged
merged 1 commit into from
Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 17 additions & 9 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,27 @@ let package = Package(
.target(
name: "Beak",
dependencies: [
"BeakCore",
"BeakCLI",
]),
.target(
name: "BeakCLI",
dependencies: [
"BeakCore",
"SwiftCLI",
]),
.target(
name: "BeakCore",
dependencies: [
"SourceKittenFramework",
"PathKit",
"SwiftCLI",
"SourceKittenFramework",
"PathKit",
"SwiftCLI",
]),
.testTarget(name: "BeakTests", dependencies: [
"BeakCore",
"Spectre",
"PathKit",
])
.testTarget(
name: "BeakTests",
dependencies: [
"BeakCore",
"Spectre",
"PathKit",
])
]
)
8 changes: 4 additions & 4 deletions Sources/Beak/main.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BeakCore
import Foundation
import BeakCLI
import BeakCore

let options = BeakOptions()
let beak = Beak(options: options)
let result = beak.execute()
exit(result)
let beak = BeakCLI(options: options)
beak.execute()
25 changes: 9 additions & 16 deletions Sources/BeakCore/Beak.swift → Sources/BeakCLI/BeakCLI.swift
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
import PathKit
import SwiftCLI
import BeakCore
import Foundation

public struct BeakOptions {

public let cachePath: Path
public let packageName: String

public init(cachePath: Path = "~/.beak/builds", packageName: String = "BeakFile") {
self.cachePath = cachePath.normalize()
self.packageName = packageName
}
}

public class Beak {
public class BeakCLI {

public let version: String = "0.3.5"
public let options: BeakOptions
Expand All @@ -21,7 +11,7 @@ public class Beak {
self.options = options
}

public func execute(arguments: [String]? = nil) -> Int32 {
public func execute(arguments: [String]? = nil) {
let cli = CLI(name: "beak", version: version, description: "Beak can inspect and run functions in your swift scripts")
cli.globalOptions.append(GlobalOptions.path)
cli.commands = [
Expand All @@ -30,10 +20,13 @@ public class Beak {
RunCommand(options: options),
EditCommand(options: options)
]

let status: Int32
if let arguments = arguments {
return cli.go(with: arguments)
status = cli.go(with: arguments)
} else {
return cli.go()
status = cli.go()
}
exit(status)
}
}
14 changes: 14 additions & 0 deletions Sources/BeakCLI/BeakError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import BeakCore
import SwiftCLI

extension BeakError: ProcessError {

public var message: String? {
return "⚠️ \(description)"
}

public var exitStatus: Int32 {
return 1
}

}
12 changes: 12 additions & 0 deletions Sources/BeakCLI/BeakOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import PathKit

public struct BeakOptions {

public let cachePath: Path
public let packageName: String

public init(cachePath: Path = "~/.beak/builds", packageName: String = "BeakFile") {
self.cachePath = cachePath.normalize()
self.packageName = packageName
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PathKit
import SwiftCLI
import BeakCore

struct GlobalOptions {
static let path = Key<String>("-p", "--path", description: "The path to a swift file. Defaults to beak.swift")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PathKit
import SwiftCLI
import BeakCore

class EditCommand: BeakCommand {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PathKit
import SwiftCLI
import BeakCore

class FunctionCommand: BeakCommand {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PathKit
import SwiftCLI
import BeakCore

class ListCommand: BeakCommand {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import PathKit
import SwiftCLI
import BeakCore

class RunCommand: BeakCommand {

Expand Down
11 changes: 1 addition & 10 deletions Sources/BeakCore/BeakError.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import SourceKittenFramework
import SwiftCLI

public enum BeakError: ProcessError, CustomStringConvertible {
public enum BeakError: Error, CustomStringConvertible {
case fileNotFound(String)
case compileError(String)
case invalidFunction(String)
Expand All @@ -20,12 +19,4 @@ public enum BeakError: ProcessError, CustomStringConvertible {
}
}

public var message: String? {
return "⚠️ \(description)"
}

public var exitStatus: Int32 {
return 1
}

}
6 changes: 3 additions & 3 deletions Sources/BeakCore/PackageManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ public class PackageManager {
public var name: String
public var beakFile: BeakFile

var sourcesPath: Path { return path + "Sources" }
var packagePath: Path { return path + "Package.swift" }
var mainFilePath: Path { return sourcesPath + "\(name)/main.swift" }
public var sourcesPath: Path { return path + "Sources" }
public var packagePath: Path { return path + "Package.swift" }
public var mainFilePath: Path { return sourcesPath + "\(name)/main.swift" }

public init(path: Path, name: String, beakFile: BeakFile) {
self.path = path
Expand Down