diff --git a/src/logue.nim b/src/logue.nim index a5dce7a..83beb4c 100644 --- a/src/logue.nim +++ b/src/logue.nim @@ -1,10 +1,10 @@ import cligen -import loguepkg/[create, execute] +import loguepkg/[create, execute, extend] proc main*() = - dispatchMulti([init], [run]) + dispatchMulti([init], [run], [extension]) when isMainModule: main() diff --git a/src/loguepkg/extend.nim b/src/loguepkg/extend.nim new file mode 100644 index 0000000..8b7c23f --- /dev/null +++ b/src/loguepkg/extend.nim @@ -0,0 +1,46 @@ +import os, strformat, osproc, strutils + +const + nimbleFile = "prologue.nimble" + + +template withDir(dir: string; body: untyped): untyped = + var curDir = getCurrentDir() + try: + setCurrentDir(dir) + body + finally: + setCurrentDir(curDir) + +proc extension*(name: seq[string]) = + if name.len == 0: + echo "Please give the name of the extension or use logue extension all to install all extensions" + else: + # TODO May raise OsError in windows + var output: string + var errC: int + if fileExists(nimbleFile): + (output, errC) = (nimbleFile, 0) + else: + (output, errC) = execCmdEx("nimble path prologue") + if errC == 0: + stripLineEnd(output) + normalizePath(output) + + withDir output: + var errC: int + + let extension = name[0] + + if extension == "all": + discard execCmd(fmt"nimble extension") + else: + try: + errC = execCmd(fmt"nimble {extension}") + except OSError: + errC = 1 + + if errC != 0: + echo "Please give the right name of the extension" + else: + echo "Please install prologue or check whther nimble is added to path"