From e84c5a721c45b18cb2f1d874e3f7e3c0db71c96d Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Fri, 20 Jun 2014 20:42:34 +0100 Subject: [PATCH] Fixes #25. --- src/babelpkg/download.nim | 6 +++--- src/babelpkg/tools.nim | 10 ++++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/babelpkg/download.nim b/src/babelpkg/download.nim index c20865a..89723fa 100644 --- a/src/babelpkg/download.nim +++ b/src/babelpkg/download.nim @@ -83,7 +83,7 @@ proc getTagsListRemote*(url: string, meth: TDownloadMethod): seq[string] = result = @[] case meth of TDownloadMethod.Git: - var (output, exitCode) = execCmdEx("git ls-remote --tags " & url) + var (output, exitCode) = doCmdEx("git ls-remote --tags " & url) if exitCode != QuitSuccess: raise newException(EOS, "Unable to query remote tags for " & url & ". Git returned: " & output) @@ -122,9 +122,9 @@ proc getHeadName*(meth: TDownloadMethod): string = proc checkUrlType*(url: string): TDownloadMethod = ## Determines the download method based on the URL. - if execCmdEx("git ls-remote " & url).exitCode == QuitSuccess: + if doCmdEx("git ls-remote " & url).exitCode == QuitSuccess: return TDownloadMethod.Git - elif execCmdEx("hg identify " & url).exitCode == QuitSuccess: + elif doCmdEx("hg identify " & url).exitCode == QuitSuccess: return TDownloadMethod.Hg else: raise newException(EBabel, "Unable to identify url.") diff --git a/src/babelpkg/tools.nim b/src/babelpkg/tools.nim index 08ea08b..ee904b6 100644 --- a/src/babelpkg/tools.nim +++ b/src/babelpkg/tools.nim @@ -9,10 +9,20 @@ type EBabel* = object of EBase proc doCmd*(cmd: string) = + let bin = cmd.split(' ')[0] + if findExe(bin) == "": + raise newException(EBabel, "'" & bin & "' not in PATH.") + let exitCode = execCmd(cmd) if exitCode != QuitSuccess: raise newException(EBabel, "Execution failed with exit code " & $exitCode) +proc doCmdEx*(cmd: string): tuple[output: TaintedString, exitCode: int] = + let bin = cmd.split(' ')[0] + if findExe(bin) == "": + raise newException(EBabel, "'" & bin & "' not in PATH.") + return execCmdEx(cmd) + template cd*(dir: string, body: stmt) = ## Sets the current dir to ``dir``, executes ``body`` and restores the ## previous working dir.