You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#!/usr/bin/env stack
-- stack --verbosity info --resolver lts-13.30 scriptmain::IO()
main =print()
The stack User's Guide says that options for stack can be specified on the second line. However, if you try the above script, the --verbosity info argument doesn't have any effect (though the --resolver lts-13.30 argument does).
At any rate - the behaviour of the above script is different, when executed, from what would happen if you ran stack --verbosity info --resolver lts-13.30 script ./myscript.hs at the shell prompt, and also from what would happen if the comment line instead said
-- stack --resolver lts-13.30 script --verbosity info
(i.e., with --verbosity info placed afterscript instead of before).
This isn't (so far as I can see) documented clearly in the User's Guide, and contradicts the output of running stack --help, which clearly says that "general" stack options like --verbosity should go before the script command:
This can be annoying if a script-user wants to, say, pass "--verbosity debug" to diagnose some problem with the script, edits the script to add that option in the usual way, and gets no change in behaviour.
Steps to reproduce
Create a script "myscript.hs":
#!/usr/bin/env stack
-- stack --verbosity info --resolver lts-13.30 scriptmain::IO()
main =print()
chmod as necessary (e.g. chmod a+rx ./myscript.hs).
Run it: ./myscript.hs.
Expected
Verbose, info-level output should be produced:
Using resolver: lts-13.30 specified on command line
()
Actual
No extra output is produced:
()
The difference is more dramatic still if you use --verbosity debug, obviously :) I can't provide any verbose output from the script in the failing case, since the bug I'm reporting prevents me from doing that. I haven't experimented to see if any other options are affected, but I assume they are (which would be bad, if they said something more important, like --compiler, say).
Either the User's Guide and the --help output are missing information about the expected behaviour of stack scripts, or the behaviour is wrong - I'm not sure which.
I think I have identified what is happening. To restate the problem, in the script interpreter:
stack --resolver lts-20.18 script --verbosity info -- Script.hs
appears to respect the 'global' option --verbosity info, while:
stack --verbosity info --resolver lts-20.18 script -- Script.hs
does not.
The reason is:
'global' options are actually parsed twice, once in the stack command and again in the script subcommand. The subcommand's parse result trumps the command's parse result. (That happens in Options.Applicative.Complicated.complicatedOptions and the line pure (mappend c a, b).)
in the interpreter, the parsing of verbosity has a default of Just LevelError. (That is set in Main.commandlineHandler.)
So, in the first example, the --verbosity info of the subcommand trumps the (hidden) default of LevelError of the stack command. In the second example the (hidden) default of LevelError of the subcommand trumps the --verbosity info of the command.
General summary/comments
Suppose you have a stack script
myscript.hs
:The stack User's Guide says that options for stack can be specified on the second line. However, if you try the above script, the
--verbosity info
argument doesn't have any effect (though the--resolver lts-13.30
argument does).At any rate - the behaviour of the above script is different, when executed, from what would happen if you ran
stack --verbosity info --resolver lts-13.30 script ./myscript.hs
at the shell prompt, and also from what would happen if the comment line instead said(i.e., with
--verbosity info
placed afterscript
instead of before).This isn't (so far as I can see) documented clearly in the User's Guide, and contradicts the output of running
stack --help
, which clearly says that "general"stack
options like--verbosity
should go before thescript
command:This can be annoying if a script-user wants to, say, pass "
--verbosity debug
" to diagnose some problem with the script, edits the script to add that option in the usual way, and gets no change in behaviour.Steps to reproduce
myscript.hs
":chmod a+rx ./myscript.hs
)../myscript.hs
.Expected
Verbose,
info
-level output should be produced:Actual
No extra output is produced:
The difference is more dramatic still if you use
--verbosity debug
, obviously :) I can't provide any verbose output from the script in the failing case, since the bug I'm reporting prevents me from doing that. I haven't experimented to see if any other options are affected, but I assume they are (which would be bad, if they said something more important, like--compiler
, say).Either the User's Guide and the
--help
output are missing information about the expected behaviour of stack scripts, or the behaviour is wrong - I'm not sure which.Stack version
Method of installation
The text was updated successfully, but these errors were encountered: