|
57 | 57 | backend*: string |
58 | 58 | compileOptions: seq[string] |
59 | 59 | of actionRun: |
60 | | - runFile: string |
| 60 | + runFile: Option[string] |
61 | 61 | compileFlags: seq[string] |
62 | 62 | runFlags*: seq[string] |
63 | 63 | of actionCustom: |
@@ -89,11 +89,11 @@ Commands: |
89 | 89 | uninstall [pkgname, ...] Uninstalls a list of packages. |
90 | 90 | [-i, --inclDeps] Uninstall package and dependent package(s). |
91 | 91 | build [opts, ...] [bin] Builds a package. |
92 | | - run [opts, ...] bin Builds and runs a package. |
93 | | - A binary name needs |
94 | | - to be specified after any compilation options, |
95 | | - any flags after the binary name are passed to |
96 | | - the binary when it is run. |
| 92 | + run [opts, ...] [bin] Builds and runs a package. |
| 93 | + Binary needs to be specified after any |
| 94 | + compilation options if there are several |
| 95 | + binaries defined, any flags after the binary |
| 96 | + or -- arg are passed to the binary when it is run. |
97 | 97 | c, cc, js [opts, ...] f.nim Builds a file inside a package. Passes options |
98 | 98 | to the Nim compiler. |
99 | 99 | test Compiles and executes tests |
@@ -266,6 +266,12 @@ proc parseCommand*(key: string, result: var Options) = |
266 | 266 | result.action = Action(typ: parseActionType(key)) |
267 | 267 | initAction(result, key) |
268 | 268 |
|
| 269 | +proc setRunOptions(result: var Options, key, val: string, isArg: bool) = |
| 270 | + if result.action.runFile.isNone() and (isArg or val == "--"): |
| 271 | + result.action.runFile = some(key) |
| 272 | + else: |
| 273 | + result.action.runFlags.add(val) |
| 274 | + |
269 | 275 | proc parseArgument*(key: string, result: var Options) = |
270 | 276 | case result.action.typ |
271 | 277 | of actionNil: |
@@ -297,10 +303,7 @@ proc parseArgument*(key: string, result: var Options) = |
297 | 303 | of actionBuild: |
298 | 304 | result.action.file = key |
299 | 305 | of actionRun: |
300 | | - if result.action.runFile.len == 0: |
301 | | - result.action.runFile = key |
302 | | - else: |
303 | | - result.action.runFlags.add(key) |
| 306 | + result.setRunOptions(key, key, true) |
304 | 307 | of actionCustom: |
305 | 308 | result.action.arguments.add(key) |
306 | 309 | else: |
@@ -371,7 +374,7 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) = |
371 | 374 | result.action.compileOptions.add(getFlagString(kind, flag, val)) |
372 | 375 | of actionRun: |
373 | 376 | result.showHelp = false |
374 | | - result.action.runFlags.add(getFlagString(kind, flag, val)) |
| 377 | + result.setRunOptions(flag, getFlagString(kind, flag, val), false) |
375 | 378 | of actionCustom: |
376 | 379 | if result.action.command.normalize == "test": |
377 | 380 | if f == "continue" or f == "c": |
@@ -441,7 +444,7 @@ proc parseCmdLine*(): Options = |
441 | 444 | else: |
442 | 445 | parseArgument(key, result) |
443 | 446 | of cmdLongOption, cmdShortOption: |
444 | | - parseFlag(key, val, result, kind) |
| 447 | + parseFlag(key, val, result, kind) |
445 | 448 | of cmdEnd: assert(false) # cannot happen |
446 | 449 |
|
447 | 450 | handleUnknownFlags(result) |
@@ -526,15 +529,23 @@ proc getCompilationFlags*(options: Options): seq[string] = |
526 | 529 | var opt = options |
527 | 530 | return opt.getCompilationFlags() |
528 | 531 |
|
529 | | -proc getCompilationBinary*(options: Options): Option[string] = |
| 532 | +proc getCompilationBinary*(options: Options, pkgInfo: PackageInfo): Option[string] = |
530 | 533 | case options.action.typ |
531 | 534 | of actionBuild, actionDoc, actionCompile: |
532 | 535 | let file = options.action.file.changeFileExt("") |
533 | 536 | if file.len > 0: |
534 | 537 | return some(file) |
535 | 538 | of actionRun: |
536 | | - let runFile = options.action.runFile.changeFileExt(ExeExt) |
| 539 | + let optRunFile = options.action.runFile |
| 540 | + let runFile = |
| 541 | + if optRunFile.get("").len > 0: |
| 542 | + optRunFile.get() |
| 543 | + elif pkgInfo.bin.len == 1: |
| 544 | + pkgInfo.bin[0] |
| 545 | + else: |
| 546 | + "" |
| 547 | + |
537 | 548 | if runFile.len > 0: |
538 | | - return some(runFile) |
| 549 | + return some(runFile.changeFileExt(ExeExt)) |
539 | 550 | else: |
540 | 551 | discard |
0 commit comments