Skip to content

Commit d53c6d0

Browse files
authored
Fix global flags not being added to runFlags after runFile (#1528)
In commit e6bb09, a change was made for adding flags to actionRun. It prevented global flags from being added to compileFlags, but also prevented global flags from being added to runFlags. This commit fixes this issue, and users can now test their CLI programs that use the same flags as nimble. For example `nimble run -- --help`.
1 parent 0bddc52 commit d53c6d0

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

src/nimblepkg/options.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -847,7 +847,8 @@ proc parseFlag*(flag, val: string, result: var Options, kind = cmdLongOption) =
847847
result.action.compileOptions.add(getFlagString(kind, flag, val))
848848
of actionRun:
849849
result.showHelp = false
850-
if not isGlobalFlag:
850+
# After runFile all flags should be added to runFlags, even if global
851+
if not isGlobalFlag or result.action.runFile.isSome():
851852
result.setRunOptions(flag, getFlagString(kind, flag, val), false)
852853
of actionCustom:
853854
if not isGlobalFlag:

tests/truncommand.nim

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ suite "nimble run":
2828
"run", # Run command invocation
2929
"run", # The command to run
3030
"--test", # First argument passed to the executed command
31-
"check" # Second argument passed to the executed command.
31+
"--help", # Second argument passed to the executed command (nimble global flag)
32+
"check" # Third argument passed to the executed command.
3233
)
3334
check exitCode == QuitSuccess
34-
check output.contains("tests$1run$1$2 --test check" %
35+
check output.contains("tests$1run$1$2 --test --help check" %
3536
[$DirSep, "run".changeFileExt(ExeExt)])
36-
check output.contains("""Testing `nimble run`: @["--test", "check"]""")
37+
check output.contains("""Testing `nimble run`: @["--test", "--help", "check"]""")
3738

3839
test "Parameters not passed to single executable":
3940
cd "run":
@@ -55,12 +56,13 @@ suite "nimble run":
5556
"run", # Run command invocation
5657
"--", # Flag to set run file to "" before next argument
5758
"--test", # First argument passed to the executed command
58-
"check" # Second argument passed to the executed command.
59+
"--help", # Second argument passed to the executed command (nimble global flag)
60+
"check" # Third argument passed to the executed command.
5961
)
6062
check exitCode == QuitSuccess
61-
check output.contains("tests$1run$1$2 --test check" %
63+
check output.contains("tests$1run$1$2 --test --help check" %
6264
[$DirSep, "run".changeFileExt(ExeExt)])
63-
check output.contains("""Testing `nimble run`: @["--test", "check"]""")
65+
check output.contains("""Testing `nimble run`: @["--test", "--help", "check"]""")
6466

6567
test "Executable output is shown even when not debugging":
6668
cd "run":

0 commit comments

Comments
 (0)