aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOskari Timperi <oskari.timperi@iki.fi>2018-04-19 22:01:09 +0100
committerOskari Timperi <oskari.timperi@iki.fi>2018-04-19 22:01:09 +0100
commitcd204dcf845aa9466e237e22624f4a4cfe18714a (patch)
treebb55f13b4a342339ab8080b4136c3f5de3cb6a54
parent55f3a493871306ac220071574e2a5897851bef54 (diff)
downloadnimpb-cd204dcf845aa9466e237e22624f4a4cfe18714a.tar.gz
nimpb-cd204dcf845aa9466e237e22624f4a4cfe18714a.zip
Use parseopt2 in nimpb_build
-rw-r--r--examples/addressbook/Makefile2
-rw-r--r--examples/simple/Makefile2
-rw-r--r--nimpb.nimble6
-rw-r--r--nimpb/compiler/nimpb_build.nim30
4 files changed, 20 insertions, 20 deletions
diff --git a/examples/addressbook/Makefile b/examples/addressbook/Makefile
index 6dbba14..ee2f023 100644
--- a/examples/addressbook/Makefile
+++ b/examples/addressbook/Makefile
@@ -7,4 +7,4 @@ reader: reader.nim addressbook_pb.nim phonenumber_pb.nim
nim c $<
%_pb.nim: %.proto
- nimpb_build -I. --out=. $<
+ nimpb_build -I=. --out=. $<
diff --git a/examples/simple/Makefile b/examples/simple/Makefile
index cec07f3..1da2b45 100644
--- a/examples/simple/Makefile
+++ b/examples/simple/Makefile
@@ -4,4 +4,4 @@ simple: simple.nim simple_pb.nim
nim c $<
%_pb.nim: %.proto
- nimpb_build -I. --out=. $<
+ nimpb_build -I=. --out=. $<
diff --git a/nimpb.nimble b/nimpb.nimble
index fbde8ea..c009e67 100644
--- a/nimpb.nimble
+++ b/nimpb.nimble
@@ -21,8 +21,8 @@ task run_conformance_tests, "Run the conformance test suite":
var testDir = "tests/conformance"
var proto = testDir / "test_messages_proto3.proto"
var testRunner = "../protobuf-3.5.1/conformance/conformance-test-runner"
- exec &"./nimpb/compiler/nimpb_build -I{testDir} --out={testDir} {proto}"
- exec &"./nimpb/compiler/nimpb_build -I{testDir} --out={testDir} {testDir}/conformance.proto"
+ exec &"./nimpb/compiler/nimpb_build -I={testDir} --out={testDir} {proto}"
+ exec &"./nimpb/compiler/nimpb_build -I={testDir} --out={testDir} {testDir}/conformance.proto"
exec &"nimble c {testDir}/conformance_nim.nim"
exec &"{testRunner} {testDir}/conformance_nim"
@@ -31,4 +31,4 @@ task gen_wkt, "Re-generate WKT's":
var outdir = "nimpb/wkt"
for proto in listFiles(incdir):
echo(&"COMPILING {proto}")
- exec &"./nimpb/compiler/nimpb_build -I{incdir} --out={outdir} {proto}"
+ exec &"./nimpb/compiler/nimpb_build -I={incdir} --out={outdir} {proto}"
diff --git a/nimpb/compiler/nimpb_build.nim b/nimpb/compiler/nimpb_build.nim
index 1abb3f3..55d5e70 100644
--- a/nimpb/compiler/nimpb_build.nim
+++ b/nimpb/compiler/nimpb_build.nim
@@ -1,5 +1,6 @@
import os
import osproc
+import parseopt2
import strformat
import strutils
@@ -7,7 +8,7 @@ import compiler
proc usage() {.noreturn.} =
echo(&"""
-{getAppFilename()} --out=OUTDIR [-IPATH [-IPATH]...] PROTOFILE...
+{getAppFilename()} --out=OUTDIR [-I=PATH [-I=PATH]...] PROTOFILE...
--out The output directory for the generated files
-I Add a path to the set of include paths
@@ -18,20 +19,19 @@ var includes: seq[string] = @[]
var protos: seq[string] = @[]
var outdir: string
-if paramCount() == 0:
- usage()
-
-for idx in 1..paramCount():
- let param = paramStr(idx)
-
- if param.startsWith("-I"):
- add(includes, param[2..^1])
- elif param.startsWith("--out="):
- outdir = param[6..^1]
- elif param == "--help":
- usage()
- else:
- add(protos, param)
+for kind, key, val in getopt():
+ case kind
+ of cmdArgument:
+ add(protos, key)
+ of cmdLongOption, cmdShortOption:
+ case key
+ of "help", "h": usage()
+ of "out": outdir = val
+ of "I": add(includes, val)
+ else:
+ echo("error: unknown option: " & key)
+ usage()
+ of cmdEnd: assert(false)
if outdir == nil:
echo("error: --out is required")