from nimble documentation (i.e. github's README.md):
Tasks support two kinds of flags: nimble <compflags> task <runflags>
. Compile flags are those specified before the task name and are forwarded to the Nim compiler that runs the .nimble task. This enables setting --define:xxx
values that can be checked with when defined(xxx)
in the task, and other compiler flags that are applicable in Nimscript mode. Run flags are those after the task name and are available as command-line arguments to the task. They can be accessed per usual from commandLineParams: seq[string]
.
commandLineParams is available in std/os
. For your example:
import std / [os, strformat]
task mytask, "my task":
echo &"my task {commandLineParams()}"
Update:
Setting up a new nimble project with the above code added and running:
nimble mytask --foo --bar
you will actually find that it prints a nim sequence with ALL arguments and not only the runtime flags. For example on Windows and anonymizing specific folder names:
my task @["e", "--hints:off", "--verbosity:0", "--colors:on", "XXX\\nimblecache-0\\test_nimble_2483249703\\test_nimble.nims", "XXY\\test_nimble\\test_nimble.nimble", "XXZ\\nimble_23136.out", "mytask", "--foo", "--bar"]
So in order to get only --foo
and --bar
you need to select arguments after mytask
Note: we probably should fix nimble docs about that.