aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoey Yakimowich-Payne <jyapayne@gmail.com>2018-06-27 22:22:38 +0900
committerJoey Yakimowich-Payne <jyapayne@gmail.com>2018-06-27 22:22:38 +0900
commita7edd8525d93ef07b3d1134067c3ab42a311d1bc (patch)
treec33eac788cac5c4a1b9d8a687bfb6d7219654b9a
parente371546d522b1ce39a1009552a43de614368279a (diff)
downloadnimgen-a7edd8525d93ef07b3d1134067c3ab42a311d1bc.tar.gz
nimgen-a7edd8525d93ef07b3d1134067c3ab42a311d1bc.zip
Rename execute to pipe
-rw-r--r--README.md2
-rw-r--r--nimgen.nim17
2 files changed, 10 insertions, 9 deletions
diff --git a/README.md b/README.md
index 0c4bb89..a92a5dc 100644
--- a/README.md
+++ b/README.md
@@ -143,7 +143,7 @@ The following keys apply to library source code (before processing) and generate
```search``` = search string providing context for following prepend/append/replace directives
-```execute``` = execute a command on a file and store the output of the command as the new file contents. Ex: execute = "cat $file | grep 'static inline'"
+```pipe``` = execute a command on a file and store the output of the command as the new file contents. Ex: pipe = "cat $file | grep 'static inline'"
```prepend``` = string value to prepend into file at beginning or before search
diff --git a/nimgen.nim b/nimgen.nim
index cff48e3..82b072a 100644
--- a/nimgen.nim
+++ b/nimgen.nim
@@ -228,11 +228,12 @@ proc prepend(file: string, data: string, search="") =
if idx != -1:
content = content[0..<idx] & data & content[idx..<content.len()]
-proc execute(file: string, command: string) =
- withFile(file):
- let cmd = command % ["file", file]
- let commandResult = execProc(cmd)
- content = commandResult
+proc pipe(file: string, command: string) =
+ let cmd = command % ["file", file]
+ let commandResult = execProc(cmd).strip()
+ if commandResult != "":
+ withFile(file):
+ content = commandResult
proc append(file: string, data: string, search="") =
withFile(file):
@@ -593,7 +594,7 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
if action == "create":
createDir(file.splitPath().head)
writeFile(file, cfg[act])
- elif action in @["prepend", "append", "replace", "comment", "rename", "compile", "dynlib", "pragma", "execute"] and sfile != "":
+ elif action in @["prepend", "append", "replace", "comment", "rename", "compile", "dynlib", "pragma", "pipe"] and sfile != "":
if action == "prepend":
if srch != "":
prepend(sfile, cfg[act], cfg[srch])
@@ -618,8 +619,8 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
c2nimConfig.dynlib.add(cfg[act])
elif action == "pragma":
c2nimConfig.pragma.add(cfg[act])
- elif action == "execute":
- execute(sfile, cfg[act])
+ elif action == "pipe":
+ pipe(sfile, cfg[act])
srch = ""
elif action == "search":
srch = act