Skip to content

Instantly share code, notes, and snippets.

@alexnask
Created May 14, 2012 23:49
Show Gist options
  • Select an option

  • Save alexnask/2698145 to your computer and use it in GitHub Desktop.

Select an option

Save alexnask/2698145 to your computer and use it in GitHub Desktop.
// Usage
new target("all", |task|
task compile("file.ooc", compile options => ["run", set("dist", "distDir")])
. print("Compiled, now cleaning")
. execute(get target("clean"))
)
new target("clean", |task|
task select("rock_tmp", ".libs") delete()
)
// Behind the scenes
CokeCore: class {
// Map of all the targets registered
targets := static HashMap<Func(Task)> new()
// Task instance to be thrown around to functions that use it; Just executes the tasks
task := static Task new()
}
Task: class {
compile: func(args: ...) {
// Do stuff
}
print: func(args: ...) {
// Do stuff
}
execute: func(args: ...) {
// Do stuff
}
select: func(args: ...) -> Files {
// Do stuff
}
}
new: class {
target: static func(name: String, f: Func(Task))
}
get: class {
target: static func(name: String) -> Func(Task)
}
// Useless class used for nicer syntax
OptionsKW: class {}
// Useless class used for nice syntax
CompileKW: class {
options := OptionsKW new()
}
compile := CompileKW new()
set: func(left, right: String) -> String {
"%s=%s" format(left, right)
}
// Class used to pass compiler options to the compile methods of a task
OptionList: class {
// Stuff here
}
operator => <T> (OptionsKW, arg: T) -> OptionList {
// Do stuff
}
// TODO: Find a nice way to expose command line arguments and environmental variables to tasks
main: func(args: ArrayList<String>) -> Int {
if(args getSize() <= 0 && !get target("all")) "Error: No target specified and target `all` not defined" println()
0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment