Commit 358d4708 authored by Drew's avatar Drew

A 'hello world' shell task

parent 70a0fa6f
import Foundation
final class Shell : Tool {
func run(args: [Yaml: Yaml]) throws {
guard let script = args["script"]?.string else { throw AnarchyBuildError.CantParseYaml("Invalid 'script' argument to shell tool.") }
let t = NSTask.launchedTaskWithLaunchPath("/bin/sh", arguments: ["-c",script])
t.waitUntilExit()
}
}
\ No newline at end of file
final class Task {
let tool: String
let name: String
let yaml: [Yaml: Yaml]
init(yaml: [Yaml:Yaml], name: String) throws {
self.yaml = yaml
self.name = name
guard let tool = yaml["tool"]?.string else {
self.tool = "undefined"
self.name = name
throw AnarchyBuildError.CantParseYaml("Missing task tool")
}
self.name = name
self.tool = tool
}
func run() {
func run() throws {
print("Running task \(name)...")
let tool = try toolByName(self.tool)
try tool.run(yaml)
}
}
\ No newline at end of file
protocol Tool {
func run(args: [Yaml: Yaml]) throws
}
let tools = ["shell":Shell()]
func toolByName(name: String) throws -> Tool {
guard let tool = tools[name] else { throw AnarchyBuildError.CantParseYaml("Unknown build tool \(name)") }
return tool
}
......@@ -10,4 +10,4 @@ print("Building package \(name)...")
guard let task = y.dictionary?["tasks"]?.dictionary else { fatalError("No tasks in YAML") }
guard let defaultTask = task["default"]?.dictionary else { fatalError("No default task in YAML") }
let t = try! Task(yaml: defaultTask, name: "default")
t.run()
\ No newline at end of file
try! t.run()
\ No newline at end of file
......@@ -16,6 +16,8 @@
3AED498D1C466DFD00AC56A8 /* Yaml.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AED49871C466DFD00AC56A8 /* Yaml.swift */; };
3AED49911C466EC200AC56A8 /* errors.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AED49901C466EC200AC56A8 /* errors.swift */; };
3AED49931C4679E800AC56A8 /* Task.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AED49921C4679E800AC56A8 /* Task.swift */; };
3AED49951C467C2300AC56A8 /* Tools.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AED49941C467C2300AC56A8 /* Tools.swift */; };
3AED49971C467C4400AC56A8 /* Shell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3AED49961C467C4400AC56A8 /* Shell.swift */; };
/* End PBXBuildFile section */
/* Begin PBXCopyFilesBuildPhase section */
......@@ -41,6 +43,8 @@
3AED49871C466DFD00AC56A8 /* Yaml.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Yaml.swift; path = ../src/yaml/Yaml.swift; sourceTree = SOURCE_ROOT; };
3AED49901C466EC200AC56A8 /* errors.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = errors.swift; path = ../src/errors.swift; sourceTree = SOURCE_ROOT; };
3AED49921C4679E800AC56A8 /* Task.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Task.swift; path = ../src/Task.swift; sourceTree = SOURCE_ROOT; };
3AED49941C467C2300AC56A8 /* Tools.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Tools.swift; path = ../src/Tools.swift; sourceTree = SOURCE_ROOT; };
3AED49961C467C4400AC56A8 /* Shell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = Shell.swift; path = ../src/Shell.swift; sourceTree = SOURCE_ROOT; };
/* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */
......@@ -77,6 +81,8 @@
3AE6851D1C466D2500444852 /* yaml */,
3AED49901C466EC200AC56A8 /* errors.swift */,
3AED49921C4679E800AC56A8 /* Task.swift */,
3AED49941C467C2300AC56A8 /* Tools.swift */,
3AED49961C467C4400AC56A8 /* Shell.swift */,
);
path = AnarchyToolsXcode;
sourceTree = "<group>";
......@@ -154,10 +160,12 @@
files = (
3AE6852B1C466DC400444852 /* main.swift in Sources */,
3AED498C1C466DFD00AC56A8 /* Tokenizer.swift in Sources */,
3AED49951C467C2300AC56A8 /* Tools.swift in Sources */,
3AED498B1C466DFD00AC56A8 /* Result.swift in Sources */,
3AED498A1C466DFD00AC56A8 /* Regex.swift in Sources */,
3AED49911C466EC200AC56A8 /* errors.swift in Sources */,
3AED49881C466DFD00AC56A8 /* Operators.swift in Sources */,
3AED49971C467C4400AC56A8 /* Shell.swift in Sources */,
3AED49891C466DFD00AC56A8 /* Parser.swift in Sources */,
3AED49931C4679E800AC56A8 /* Task.swift in Sources */,
3AED498D1C466DFD00AC56A8 /* Yaml.swift in Sources */,
......
......@@ -45,5 +45,21 @@
endingLineNumber = "1">
</BreakpointContent>
</BreakpointProxy>
<BreakpointProxy
BreakpointExtensionID = "Xcode.Breakpoint.FileBreakpoint">
<BreakpointContent
shouldBeEnabled = "No"
ignoreCount = "0"
continueAfterRunningActions = "No"
filePath = "../src/Shell.swift"
timestampString = "474382081.524901"
startingColumnNumber = "9223372036854775807"
endingColumnNumber = "9223372036854775807"
startingLineNumber = "4"
endingLineNumber = "4"
landmarkName = "run(_:)"
landmarkType = "5">
</BreakpointContent>
</BreakpointProxy>
</Breakpoints>
</Bucket>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment