Skip to content

Commit

Permalink
extension
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Sep 15, 2020
1 parent 1e7b5c1 commit fd123d6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/logue.nim
Original file line number Diff line number Diff line change
@@ -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()
46 changes: 46 additions & 0 deletions src/loguepkg/extend.nim
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit fd123d6

Please sign in to comment.