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

Warn that scripts cannot be package executables #10326

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions doc/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ the following file named ``myscript``:
main :: IO ()
main = haskellSay "Hello, Haskell!"

The necessary sections of a ``.cabal`` file are placed
directly into the script as a comment.
The necessary sections of a package description that would otherwise be in a
``.cabal`` file are placed directly into the script as a comment.

Use the familiar ``cabal run`` command to execute this script:

Expand All @@ -222,6 +222,36 @@ can be run directly after setting the execute permission (+x):

See more in the documentation for :ref:`cabal run`.

.. warning::

Single-file scripts cannot also be part of a package, as an executable or
listed as a module.

.. code-block:: console

$ cat script-exclusivity.cabal
cabal-version: 3.0
name: script-exclusitivity
version: 1

executable my-script-exe
build-depends:
base,
haskell-say
main-is: myscript.hs

$ ./myscript.hs
Error: [Cabal-7070]
The run command can only run an executable as a whole, not files or modules
within them, but the target 'myscript.hs' refers to the file myscript.hs in the
executable my-script-exe.

$ cabal run myscript.hs
Error: [Cabal-7070]
The run command can only run an executable as a whole, not files or modules
within them, but the target 'myscript.hs' refers to the file myscript.hs in the
executable my-script-exe.

philderbeast marked this conversation as resolved.
Show resolved Hide resolved
What Next?
----------

Expand Down
Loading