Created
August 5, 2016 17:50
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import myutils | |
proc preRun(): int = | |
#...sets up the environment with globals and whatnot... | |
discard | |
proc initHandler(idx: int, vargs: seq[string], env: HandleEnvironment): int {.gcsafe.} = | |
#...code stuff... | |
discard | |
# all procs in the table are the same as initHandler | |
var | |
commands = toTable({ | |
"init": initHandler, | |
"build": buildHandler, | |
"integration": integrationHandler, | |
"help": helpHandler, | |
"hotswap": hotswapHandler, | |
"log": logHandler, | |
"search": searchHandler, | |
# Temporary handler for testing various bits and bobs | |
"test": testHandler | |
}) | |
idx = 0 | |
params = commandLineParams() | |
param: string | |
environment: HandleEnvironment | |
allCommands = toSet(toSeq(commands.keys())) | |
environment = HandleEnvironment( | |
branch: branch, | |
workingDir: workingDir, | |
branchlessWorkingDir: branchlessWorkingDir, | |
storagePath: storagePath, | |
allCommands: allCommands) | |
idx += preRun(params) | |
if params.len() == 0: | |
printHelp() | |
quit(1) | |
else: | |
while idx < params.len(): | |
param = params[idx] | |
if commands.hasKey(param): | |
idx += commands[param](idx, params, environment) + 1 | |
else: | |
echo "'", param, "' is not a valid command." | |
printHelp() | |
quit(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type | |
HandleEnvironment* = ref object | |
branch*: string | |
workingDir*: string | |
branchlessWorkingDir*: string | |
storagePath*: string | |
allCommands*: HashSet[string] | |
# ...and other useful stuff |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import myutils | |
proc searchHandler*(idx: int, vargs: seq[string], env: HandleEnvironment): int {.procvar, gcsafe.} = | |
discard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment