Skip to content

Commit ead651d

Browse files
committed
Fix #5322 Extend stack exec --help docs and consequent changes
Adds, to `stack exec --help`, `If the command is absent, the first of any arguments is taken as the command.` Given that change, expands the meta variables to `COMMAND` (from `CMD`) and `ARGUMENT(S)` (from `ARG`). The `(S)` is used to indicate one or more arguments. Changes the example from `stack exec -- ghc-pkg describe base` to `stack exec ghc-pkg -- describe base`, to follow the alternative actually presented by `stack exec --help`. In addition, for consistency throughout: - Changes, throughout, the meta variable of `--package` to `PACKAGE(S)` (from default `ARG`), to avoid confusion over different references to 'arguments'. Also changes `Additional packages` to `Additional package(s)` to indicate one or more packages. - Makes consistent changes to `stack script --help`. - Makes consistent changes to `stack build --help` in respect of the `--exec` option. - Makes consistent changes to `stack hoogle --help`, which referred to `'stack exec' synatax`. Also, rather than cross-refer user to `stack exec`, refers to `the '-- ARGUMENT(S)' syntax` and conforms to the `stack exec --help` approach of giving an example also after `-- ARGUMENT(S)`.
1 parent 1b1bed5 commit ead651d

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

src/Stack/Config.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import Distribution.Version (simplifyVersionRange, mkVersion')
5353
import GHC.Conc (getNumProcessors)
5454
import Lens.Micro ((.~))
5555
import Network.HTTP.StackClient (httpJSON, parseUrlThrow, getResponseBody)
56-
import Options.Applicative (Parser, strOption, long, help)
56+
import Options.Applicative (Parser, help, long, metavar, strOption)
5757
import Path
5858
import Path.Extra (toFilePathNoTrailingSep)
5959
import Path.Find (findInParents)
@@ -944,7 +944,10 @@ getDefaultUserConfigPath stackRoot = do
944944
return path
945945

946946
packagesParser :: Parser [String]
947-
packagesParser = many (strOption (long "package" <> help "Additional packages that must be installed"))
947+
packagesParser = many (strOption
948+
(long "package" <>
949+
metavar "PACKAGE(S)" <>
950+
help "Additional package(s) that must be installed"))
948951

949952
defaultConfigYaml :: IsString s => s
950953
defaultConfigYaml =

src/Stack/Options/BuildParser.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ buildOptsParser cmd =
7676
help "Watch all local files not taking targets into account") <*>
7777
many (cmdOption
7878
(long "exec" <>
79-
metavar "CMD [ARGS]" <>
80-
help "Command and arguments to run after a successful build")) <*>
79+
metavar "COMMAND [ARGUMENT(S)]" <>
80+
help "Command and argument(s) to run after a successful build")) <*>
8181
switch
8282
(long "only-configure" <>
8383
help

src/Stack/Options/ExecParser.hs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ execOptsParser mcmd =
1616
<*> eoArgsParser
1717
<*> execOptsExtraParser
1818
where
19-
eoCmdParser = ExecCmd <$> strArgument (metavar "CMD" <> completer projectExeCompleter)
19+
eoCmdParser = ExecCmd <$> strArgument (metavar "COMMAND" <> completer projectExeCompleter)
2020
eoArgsParser = many (strArgument (metavar txt))
2121
where
2222
txt = case mcmd of
2323
Nothing -> normalTxt
2424
Just ExecCmd{} -> normalTxt
25-
Just ExecRun -> "-- ARGS (e.g. stack run -- file.txt)"
26-
Just ExecGhc -> "-- ARGS (e.g. stack runghc -- X.hs -o x)"
27-
Just ExecRunGhc -> "-- ARGS (e.g. stack runghc -- X.hs)"
28-
normalTxt = "-- ARGS (e.g. stack exec -- ghc-pkg describe base)"
25+
Just ExecRun -> "-- ARGUMENT(S) (e.g. stack run -- file.txt)"
26+
Just ExecGhc -> "-- ARGUMENT(S) (e.g. stack runghc -- X.hs -o x)"
27+
Just ExecRunGhc -> "-- ARGUMENT(S) (e.g. stack runghc -- X.hs)"
28+
normalTxt = "-- ARGUMENT(S) (e.g. stack exec ghc-pkg -- describe base)"
2929

3030
evalOptsParser :: String -- ^ metavar
3131
-> Parser EvalOpts
@@ -59,7 +59,10 @@ execOptsExtraParser = ExecOptsExtra
5959
<*> pure True
6060

6161
eoPackagesParser :: Parser [String]
62-
eoPackagesParser = many (strOption (long "package" <> help "Additional packages that must be installed"))
62+
eoPackagesParser = many
63+
(strOption (long "package"
64+
<> help "Additional package(s) that must be installed"
65+
<> metavar "PACKAGE(S)"))
6366

6467
eoRtsOptionsParser :: Parser [String]
6568
eoRtsOptionsParser = concat <$> many (argsOption

src/Stack/Options/ScriptParser.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ data ScriptExecute
2424

2525
scriptOptsParser :: Parser ScriptOpts
2626
scriptOptsParser = ScriptOpts
27-
<$> many (strOption (long "package" <> help "Additional packages that must be installed"))
27+
<$> many (strOption
28+
(long "package" <>
29+
metavar "PACKAGE(S)" <>
30+
help "Additional package(s) that must be installed"))
2831
<*> strArgument (metavar "FILE" <> completer (fileExtCompleter [".hs", ".lhs"]))
29-
<*> many (strArgument (metavar "-- ARGS (e.g. stack script X.hs -- args to program)"))
32+
<*> many (strArgument (metavar "-- ARGUMENT(S) (e.g. stack script X.hs -- argument(s) to program)"))
3033
<*> (flag' SECompile
3134
( long "compile"
3235
<> help "Compile the script without optimization and run the executable"

src/main/Main.hs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,12 @@ commandLineHandler currentDir progName isInterpreter = complicatedOptions
277277
execCmd
278278
(execOptsParser $ Just ExecGhc)
279279
addCommand' "hoogle"
280-
("Run hoogle, the Haskell API search engine. Use 'stack exec' syntax " ++
281-
"to pass Hoogle arguments, e.g. stack hoogle -- --count=20 or " ++
282-
"stack hoogle -- server --local")
280+
("Run hoogle, the Haskell API search engine. Use the '-- ARGUMENT(S)' syntax " ++
281+
"to pass Hoogle arguments, e.g. stack hoogle -- --count=20, or " ++
282+
"stack hoogle -- server --local.")
283283
hoogleCmd
284-
((,,,) <$> many (strArgument (metavar "ARG"))
284+
((,,,) <$> many (strArgument
285+
(metavar "-- ARGUMENT(S) (e.g. stack hoogle -- server --local)"))
285286
<*> boolFlags
286287
True
287288
"setup"
@@ -297,7 +298,7 @@ commandLineHandler currentDir progName isInterpreter = complicatedOptions
297298

298299
-- These are the only commands allowed in interpreter mode as well
299300
addCommand' "exec"
300-
"Execute a command"
301+
"Execute a command. If the command is absent, the first of any arguments is taken as the command."
301302
execCmd
302303
(execOptsParser Nothing)
303304
addCommand' "run"

0 commit comments

Comments
 (0)