Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import strformat, strutils, tables
- type Task = object
- requires*: seq[string]
- actions*: string
- name*: string
- proc `$`(this: Task): string =
- return fmt("Task {this.name} Requirements: {this.requires} , actions {this.actions}")
- type Bake = ref object of RootObj
- tasks* : TableRef[string, Task]
- proc addTask*(this: Bake, taskname: string, deps: seq[string], actions:string) : void =
- var t = Task(name:taskname, requires:deps, actions:actions)
- this.tasks.add(taskname, t)
- proc runTaskHelper(this: Bake, taskname: string, deps: var seq[string]) : void
- proc runTask*(this: Bake, taskname: string): void =
- var deps = newSeq[string]()
- this.runTaskHelper(taskname, deps)
- for tsk in deps:
- let t = this.tasks.getOrDefault(tsk)
- echo(t.actions)
- proc runTaskHelper(this: Bake, taskname: string, deps: var seq[string]) : void =
- var tsk = this.tasks.getOrDefault(taskname)
- echo "TASK IN RUNTASKHELPER: " & $tsk & " DEPS NOW" & $deps
- if len(tsk.requires) > 0:
- for c in tsk.requires:
- echo "C NOW IS " & c
- this.runTaskHelper(c, deps)
- else:
- deps.add(taskname)
- echo "T ADDING TASK TO DEPS SK: " & $tsk & " DEPS: " & $deps
- proc main() =
- var b = new Bake
- b.tasks = newTable[string, Task]()
- b.add_task("publish", @["build-release"], "print publish")
- b.add_task("build-release", @["nim-installed"], "print exec command to build release mode")
- b.add_task("nim-installed", @["curl-installed", "bash-installed"], "print curl LINK | bash")
- b.add_task("curl-installed", @["apt-installed"], "apt-get install curl")
- b.add_task("bash-installed", @["apt-installed"], "apt-get install bash")
- b.add_task("apt-installed", @[], "code to install apt...")
- b.run_task("publish")
- when isMainModule:
- main()
Advertisement
Add Comment
Please, Sign In to add comment