aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgenotrance <dev@genotrance.com>2018-07-07 14:30:21 -0500
committerGitHub <noreply@github.com>2018-07-07 14:30:21 -0500
commit1b645dd5b23d9fc435117d5f20f8bb024c0e1f52 (patch)
tree85d7b6713ff65461b4d46497b74a508d0c03f09a
parentd943f117c4860eb5f069212989e73f17b981881d (diff)
parenta7edd8525d93ef07b3d1134067c3ab42a311d1bc (diff)
downloadnimgen-1b645dd5b23d9fc435117d5f20f8bb024c0e1f52.tar.gz
nimgen-1b645dd5b23d9fc435117d5f20f8bb024c0e1f52.zip
Merge pull request #6 from jyapayne/add_execute_for_files
Add support for executing a command on a file.
-rw-r--r--README.md2
-rw-r--r--nimgen.nim11
2 files changed, 12 insertions, 1 deletions
diff --git a/README.md b/README.md
index d47239e..a92a5dc 100644
--- a/README.md
+++ b/README.md
@@ -143,6 +143,8 @@ The following keys apply to library source code (before processing) and generate
```search``` = search string providing context for following prepend/append/replace directives
+```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
```append``` = string value to append into file at the end or after search
diff --git a/nimgen.nim b/nimgen.nim
index d11d623..545c3be 100644
--- a/nimgen.nim
+++ b/nimgen.nim
@@ -229,6 +229,13 @@ proc prepend(file: string, data: string, search="") =
if idx != -1:
content = content[0..<idx] & data & content[idx..<content.len()]
+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):
if search == "":
@@ -588,7 +595,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"] 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])
@@ -613,6 +620,8 @@ proc runFile(file: string, cfgin: OrderedTableRef) =
c2nimConfig.dynlib.add(cfg[act])
elif action == "pragma":
c2nimConfig.pragma.add(cfg[act])
+ elif action == "pipe":
+ pipe(sfile, cfg[act])
srch = ""
elif action == "search":
srch = act