Skip to content

Instantly share code, notes, and snippets.

@Freezerburn
Created August 5, 2016 17:50
Show Gist options
  • Save Freezerburn/c16071e48756b0e8e8e04c53e303bffa to your computer and use it in GitHub Desktop.
Save Freezerburn/c16071e48756b0e8e8e04c53e303bffa to your computer and use it in GitHub Desktop.
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)
type
HandleEnvironment* = ref object
branch*: string
workingDir*: string
branchlessWorkingDir*: string
storagePath*: string
allCommands*: HashSet[string]
# ...and other useful stuff
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