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

Support multiline script interpreter directive for better readability #1394

Closed
harendra-kumar opened this issue Nov 21, 2015 · 9 comments · Fixed by #1470
Closed

Support multiline script interpreter directive for better readability #1394

harendra-kumar opened this issue Nov 21, 2015 · 9 comments · Fixed by #1470

Comments

@harendra-kumar
Copy link
Collaborator

When we have many packages to be specified on the embedded stack command the comment line can become too long. It would be nice to support a multiline comment so that it can formatted for better readability. Like this:

{- stack --verbosity silent 
         --resolver lts-3.14 
         --install-ghc runghc 
         --package system-filepath 
         --package system-argv0 
         --package random 
         --package argparser
         ...
-}

Further comments from the stack mailing list:

Perhaps {-# OPTIONS_STACK ... #-} would be a more standard syntax for it?

I'd worry about that being confused with compiler pragmas, and people expecting to to be used in all cases (i.e. by stack build as well). Since this only applies when using stack as a script interpreter, that would be misleading.

@mgsloan
Copy link
Contributor

mgsloan commented Nov 22, 2015

I agree, this would be nice. Feel free to open a PR implementing it.

@borsboom
Copy link
Contributor

This is especially important if we want to have a --explicit-packages flag as mentioned in #1388 (and related to #1208). That package list is likely to be quite long which would be unwieldy with the current single-line approach.

@harendra-kumar
Copy link
Collaborator Author

I am assuming we are keeping the current comment format starting with "--" as well. This is useful for the common case of shorter commands.

A few minor points regarding the interpreter implementation:

  • The current implementation requires a space after "--". We can relax that to make the syntax more permissive rather than documenting the nuances.
  • We should make it clear in the documentation that the comment should immediately follow the shebang line. No blank lines are allowed in between.
  • Currently stack prints some output of its own before running the script:

Run from outside a project, using implicit global project config
Using resolver: lts-3.14 from implicit global project's config file: /var/home/harendra/.stack/global-project/stack.yaml

When used as interpreter no other output is desirable other than the script's output itself. In fact this should hold true for any stack exec command. That might interfere with the processing of the script output.

  • --install-ghc could be a bit time consuming operation and a largish download. How about a command line option to ask the user - something like --install-ghc=ask?

@mgsloan
Copy link
Contributor

mgsloan commented Nov 27, 2015

  • The current implementation requires a space after "--". We can relax that to make the syntax more permissive rather than documenting the nuances.
  • We should make it clear in the documentation that the comment should immediately follow the shebang line. No blank lines are allowed in between.

Agreed on both points.

When used as interpreter no other output is desirable other than the script's output itself. In fact this should hold true for any stack exec command. That might interfere with the processing of the script output.

It may be problematic to support this given --install-ghc. One thing that might be helpful is that all that info logging goes to stderr, so if you only care about the stdout of a script, things will work fine.

--install-ghc could be a bit time consuming operation and a largish download. How about a command line option to ask the user - something like --install-ghc=ask?

So far, stack hasn't added much interactivity, in order to make it easily scriptable. We don't necessarily need to stick to this principle everywhere, though, this seems like a reasonable thing to have.

@soenkehahn
Copy link

Regarding stack adding output: I would prefer if stack told me when it has to download something, be it ghc or packages from hackage. Or if it has to compile a dependency. Any such output has to go to stderr (as @mgsloan said). If nothing has to be downloaded or compiled because everything is already cached in ~/.stack, I think stack shouldn't add anything, not even to stderr.

@harendra-kumar
Copy link
Collaborator Author

I agree completely.

@mgsloan
Copy link
Contributor

mgsloan commented Nov 30, 2015

@soenkehahn Yup, sounds good to me!

@harendra-kumar
Copy link
Collaborator Author

Another problem that I found with the implementation - if we have a file in the current directory whose name matches any of the stack commands then instead of running the command stack will execute the file as an interpreter. Here is an example:

cueball $ cat build
-- stack --verbosity silent runghc

main = putStrLn "Hello there!"
cueball $ stack build
Hello there!

@mgsloan
Copy link
Contributor

mgsloan commented Dec 3, 2015

@harendra-kumar Whoah, yeah, that should be fixed.

harendra-kumar added a commit to harendra-kumar/stack that referenced this issue Dec 5, 2015
Multi line block comments can now be used for additional stack arguments
when stack is used as script interpreter. Like this:

{- stack
  --verbosity silent
  --resolver lts-3.14
  --install-ghc
  runghc
  --package random
  --package system-argv0
-}

Newlines are ignored in the block comments. This allows for better
formatting of longer commands.

Previous single line format is supported as usual. The single line
syntax now allows a missing space between comment marker and the start
of command i.e. "--stack ..." too works now.

Updated the guide with complete syntax and semantics.

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

Successfully merging a pull request may close this issue.

4 participants