Distribution.Client.CmdRun

cabal-install-3.12.1.0: The command-line interface for Cabal and Hackage.

Safe Haskell | None
Language | Haskell2010

Distribution.Client.CmdRun

Contents

- The `run` CLI and action
- Internals exposed for testing

Description

cabal-install CLI command: run

Synopsis

- runCommand :: CommandUI (NixStyleFlags ())
- runAction :: NixStyleFlags () -> [String] -> GlobalFlags -> IO ()
- handleShebang :: FilePath -> [String] -> IO ()
- validScript :: String -> IO Bool
- matchesMultipleProblem :: TargetSelector -> [AvailableTarget ()] -> RunTargetProblem
- noExesProblem :: TargetSelector -> RunTargetProblem
- selectPackageTargets :: TargetSelector -> [AvailableTarget k] -> Either RunTargetProblem [k]
- selectComponentTarget :: SubComponentTarget -> AvailableTarget k -> Either RunTargetProblem k

# The `run` CLI and action

runCommand :: CommandUI (NixStyleFlags ()) #

runAction :: NixStyleFlags () -> [String] -> GlobalFlags -> IO () #

The `run` command runs a specified executable-like component, building it first if necessary. The component can be either an executable, a test, or a benchmark. This is particularly useful for passing arguments to exestestsbenchs by simply appending them after a `--`.

For more details on how this works, see the module Distribution.Client.ProjectOrchestration

handleShebang :: FilePath -> [String] -> IO () #

Handle `cabal` invoked as script interpreter, see also `validScript`

First argument is the `FilePath` to the script to be executed; second argument is a list of arguments to be passed to the script.

validScript :: String -> IO Bool #

Used by the main CLI parser as heuristic to decide whether `cabal` was invoked as a script interpreter, i.e. via

    #! /usr/bin/env cabal

or

    #! /usr/bin/cabal

As the first argument passed to `cabal` will be a filepath to the script to be interpreted.

See also `handleShebang`

# Internals exposed for testing

matchesMultipleProblem :: TargetSelector -> [AvailableTarget ()] -> RunTargetProblem #

noExesProblem :: TargetSelector -> RunTargetProblem #

selectPackageTargets :: TargetSelector -> [AvailableTarget k] -> Either RunTargetProblem [k] #

This defines what a `TargetSelector` means for the `run` command. It selects the `AvailableTarget`s that the `TargetSelector` refers to, or otherwise classifies the problem.

For the `run` command we select the exe if there is only one and it's buildable. Fail if there are no or multiple buildable exe components.

selectComponentTarget :: SubComponentTarget -> AvailableTarget k -> Either RunTargetProblem k #

For a `TargetComponent` `TargetSelector`, check if the component can be selected.

For the `run` command we just need to check it is a executable-like (an executable, a test, or a benchmark), in addition to the basic checks on being buildable etc.