Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No debug output with -v in interpreter mode #2343

Open
sjakobi opened this issue Jul 6, 2016 · 9 comments
Open

No debug output with -v in interpreter mode #2343

sjakobi opened this issue Jul 6, 2016 · 9 comments

Comments

@sjakobi
Copy link
Member

sjakobi commented Jul 6, 2016

I would like to see what stack is doing when it's running a script but it currently refuses:

Take turtle.hs:

#!/usr/bin/env stack
-- stack -v --resolver lts-6.6 --install-ghc runghc --package turtle

{-# LANGUAGE OverloadedStrings #-}
import Turtle
main = echo "Hello World!"
~ $ ./turtle.hs
~ $ ./turtle.hs 
Completed 5 action(s).
Hello World!

stack -v turtle.hs isn't even valid syntax:

~ $ stack -v turtle.hs 
Invalid argument `turtle.hs'
File does not exist or is not a regular file `-v'
<snip>

Is there a reason why we can't override script options by passing them to stack <options> script?

@harendra-kumar
Copy link
Collaborator

I know, you can only specify the file on command line, no options. Though you can specify the options in the interpreter command in the script and -v should work there. I use it that way and it works, is that too not working for you?

There are a couple of problems in using the command line options in the interpreter mode:

  1. The interpreter command line options parsing is a big hack. The command line arguments are first passed to the regular options parser, the Invalid argument message that you see is coming from that. We internally check for this Invalid argument string in the failure callback of options parser and fallback to interpreterHandler which has a very simple parser - it expects the first thing in the command as the file to interpret. To be able to understand options either the regular options parser itself will have to somehow understand and handle the interpreter syntax. or the fallback handler will have to build an options parser which can handle all options with interpreter syntax.

  2. Even if we are able to parse the options the next hurdle is to combine them with the command specified inside the script file. The interpreterHandler parses the command specified in the script and invokes this without any modifications, that is the real final stack command that we are running. If we are to use the options from the initial command line then we will have to somehow combine them with the command specified in the script file. Can we do that simply and easily without running into problems?

I did not pursue it further because of these issues. The effort involved in solving them perhaps is not worth the gain especially when we have a way to specify the options in the script file itself.

One low hanging enhancement could be to improve the message that we are seeing. When interpreterHandler fails (or maybe when we see an argument starting with a -), we can say something to the tune of:

Command line options are not allowed when using stack as script interpreter. 
The effective stack command is the one specified inside the script. 
The command line usage is:

stack <script path>

@sjakobi
Copy link
Member Author

sjakobi commented Jul 6, 2016

Though you can specify the options in the interpreter command in the script and -v should work there. I use it that way and it works, is that too not working for you?

When I run the following script (notice the -v) I get no debug output. Do you?

#!/usr/bin/env stack
-- stack -v --resolver lts-6.6 --install-ghc runghc --package turtle

{-# LANGUAGE OverloadedStrings #-}
import Turtle
main = echo "Hello World!"

@harendra-kumar
Copy link
Collaborator

This works:

#!/usr/bin/env stack
-- stack --resolver lts-6.3 runghc -v --package turtle

@harendra-kumar
Copy link
Collaborator

BTW, I see PR #2318 trying to fix exactly this.

@sjakobi
Copy link
Member Author

sjakobi commented Jul 6, 2016

This works:

#!/usr/bin/env stack
-- stack --resolver lts-6.3 runghc -v --package turtle

Ah, awesome!

@harendra-kumar
Copy link
Collaborator

We need to get the following also to work:

 #!/usr/bin/env stack
-- stack -v --resolver lts-6.6 --install-ghc runghc --package turtle

#1472 introduced silent mode when interpreting a script but we should be able to override that via command line.

@sjakobi
Copy link
Member Author

sjakobi commented Feb 17, 2017

We need to get the following also to work:

#!/usr/bin/env stack
-- stack -v --resolver lts-6.6 --install-ghc runghc --package turtle

The situation is the same with the new script command.

@mgsloan
Copy link
Contributor

mgsloan commented Feb 18, 2017

Note that now the script interpreter is not totally silent - it outputs logErrors - ccd5994

@mgsloan
Copy link
Contributor

mgsloan commented Mar 19, 2017

Oddly enough, the following does work

#!/usr/bin/env stack
-- stack --resolver lts-6.6 --install-ghc runghc --package turtle -v

Not sure why moving the -v to the end makes any difference... When running outside the script interpreter it doesn't make a difference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants