diff --git a/ChangeLog.md b/ChangeLog.md index 402af42e41..7fb9ca5201 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -10,7 +10,8 @@ Major changes: Behavior changes: -* `stack list` outputs to standard output rather than to standard error. +* `stack list`, `stack templates` and `stack uninstall` output to the standard + output stream rather than to the standard error stream. Other enhancements: @@ -185,7 +186,7 @@ Behavior changes: [Haskell Error Index](https://errors.haskell.org/) initiative, all Stack error messages generated by Stack itself begin with an unique code in the form `[S-nnnn]`, where `nnnn` is a four-digit number. -* Test suite executables that seek input on the standard input channel (`stdin`) +* Test suite executables that seek input on the standard input stream (`stdin`) will not throw an exception. Previously, they would thow an exception, consistent with Cabal's 'exitcode-stdio-1.0' test suite interface specification. Pass the flag `--no-tests-allow-stdin` to `stack build` to diff --git a/doc/build_command.md b/doc/build_command.md index 15c5a76604..04a393bb38 100644 --- a/doc/build_command.md +++ b/doc/build_command.md @@ -555,14 +555,14 @@ package is targetted in a multi-package project (for example, using `stack build `). * **One target package:** The build output for the target package is sent to the - standard error output stream of the console as it happens. + standard error stream of the console as it happens. * **More than one target package:** The build output from GHC (as opposed to from Stack) for each target package is sent to a log file for that package, unless an error occurs that prevents that. At the end of the build, the location of the directory containing the log files is reported. To also output - the contents of the log files to the standard error output stream of the - console at the end of the build, use Stack's `dump-logs` option. For further + the contents of the log files to the standard error stream of the console at + the end of the build, use Stack's `dump-logs` option. For further information about that option, see the [YAML configuration](yaml_configuration.md#dump-logs) documentation. The default `dump-logs` mode is to output the contents of the log files that are @@ -606,10 +606,10 @@ Default: Enabled Cabal defines a test suite interface ['exitcode-stdio-1.0'](https://hackage.haskell.org/package/Cabal-syntax-3.8.1.0/docs/Distribution-Types-TestSuiteInterface.html#v:TestSuiteExeV1.0) where the test suite takes the form of an executable and the executable takes -nothing on the standard input channel (`stdin`). Pass this flag to override that -specification and allow the executable to receive input on that channel. If you +nothing on the standard input stream (`stdin`). Pass this flag to override that +specification and allow the executable to receive input on that stream. If you pass `--no-tests-allow-stdin` and the executable seeks input on the standard -input channel, an exception will be thown. +input stream, an exception will be thown. ## Examples diff --git a/doc/dot_command.md b/doc/dot_command.md index a332aaddaf..aa64240a35 100644 --- a/doc/dot_command.md +++ b/doc/dot_command.md @@ -15,7 +15,7 @@ graphs and the `dot` executable for drawing directed graphs. Graphviz is available to [download](https://www.graphviz.org/download/) for Linux, Windows, macOS and FreeBSD. -`stack dot` produces output, to the standard output channel, in the DOT language +`stack dot` produces output, to the standard output stream, in the DOT language to represent the relationships between your packages and their dependencies. By default: diff --git a/doc/global_flags.md b/doc/global_flags.md index 671e2f0aca..731d469a21 100644 --- a/doc/global_flags.md +++ b/doc/global_flags.md @@ -87,8 +87,8 @@ specific configuration [option](yaml_configuration.md#ghc-variant). ## `--hpack-numeric-version` flag Pass the flag `--hpack-numeric-version` to cause Stack to report the numeric -version of its built-in Hpack library to standard output (e.g. `0.35.0`) and -quit. +version of its built-in Hpack library to the standard output stream (e.g. +`0.35.0`) and quit. ## `--[no-]install-ghc` flag @@ -158,7 +158,7 @@ Stack can be configured to integrate with Nix. For further information, see ## `--numeric-version` flag Pass the flag `--numeric-version` to cause Stack to report its numeric version -to standard output (e.g. `2.9.1`) and quit. +to the standard output stream (e.g. `2.9.1`) and quit. ## `--[no-]plan-in-log` flag diff --git a/doc/ide_command.md b/doc/ide_command.md index 279decf15a..84f92a8fca 100644 --- a/doc/ide_command.md +++ b/doc/ide_command.md @@ -24,8 +24,8 @@ stack ide packages [--stdout] [--cabal-files] By default: -* its output is sent to the standard error channel. Pass the flag `--stdout` to - change to the standard output channel; and +* its output is sent to the standard error stream. Pass the flag `--stdout` to + change to the standard output stream; and * the output is the package name (without its version). Pass the flag `--cabal-files` to change to the full path to the package's Cabal file. @@ -39,8 +39,8 @@ stack ide targets [--exes] [--tests] [--benchmarks] [--stdout] or more of the flags `--exes`, `--tests` and `--benchmarks` to list only targets of those component types. -By default, its output is sent to the standard error channel. Pass the flag -`--stdout` to change to the standard output channel. +By default, its output is sent to the standard error stream. Pass the flag +`--stdout` to change to the standard output stream. For example, for the Stack project itself, command: diff --git a/doc/list_command.md b/doc/list_command.md index 6061388f6b..b84b3bb8d2 100644 --- a/doc/list_command.md +++ b/doc/list_command.md @@ -8,21 +8,22 @@ stack list [PACKAGE] ~~~ -`stack list ` will list the latest version of the package from -Hackage. If the package name cannot be found on Hackage, even after updating the -package index, suggestions (not necessarily good ones) will be made about the -intended package name. +`stack list ` will send to the standard output stream the latest +version of the package from Hackage. If the package name cannot be found on +Hackage, even after updating the package index, suggestions (not necessarily +good ones) will be made about the intended package name. -`stack --resolver list ` will list the version of the -package in the specified snapshot, unless the package comes with GHC on -Unix-like operating systems. If the package name cannot be found in the -snapshot, the command will fail, identifying only the package(s) that did not -appear in the snapshot. +`stack --resolver list ` will send to the standard +output stream the version of the package in the specified snapshot, unless the +package comes with GHC on Unix-like operating systems. If the package name +cannot be found in the snapshot, the command will fail, identifying only the +package(s) that did not appear in the snapshot. More than one package name can be specified. -`stack --resolver list` will list all the packages in the specified -snapshot, except those which come with GHC on Unix-like operating systems. +`stack --resolver list` will send to the standard output stream a +list of all the packages in the specified snapshot, except those which come with +GHC on Unix-like operating systems. For example: diff --git a/doc/templates_command.md b/doc/templates_command.md index ef0f5d2b1e..76fab60661 100644 --- a/doc/templates_command.md +++ b/doc/templates_command.md @@ -6,8 +6,8 @@ stack templates ~~~ -`stack templates` provides information about project templates used with the -[`stack new` command](new_command.md). +`stack templates` provides information to the standard output stream about +project templates used with the [`stack new` command](new_command.md). Project templates are specified in `.hsfiles` files. The format of those files is documented at the diff --git a/doc/uninstall_command.md b/doc/uninstall_command.md index afe34465ed..411c879fb7 100644 --- a/doc/uninstall_command.md +++ b/doc/uninstall_command.md @@ -6,6 +6,6 @@ stack uninstall ~~~ -`stack uninstall` provides information about how to uninstall Stack or a -Stack-supplied tool (such as GHC or, on Windows, MSYS2). It does not -itself uninstall Stack or a Stack-supplied tool. +`stack uninstall` provides information to the standard output stream about how +to uninstall Stack or a Stack-supplied tool (such as GHC or, on Windows, MSYS2). +It does not itself uninstall Stack or a Stack-supplied tool. diff --git a/doc/yaml_configuration.md b/doc/yaml_configuration.md index a3d1e5fd24..4739b1ee90 100644 --- a/doc/yaml_configuration.md +++ b/doc/yaml_configuration.md @@ -796,8 +796,8 @@ unless an error occurs that prevents that. For further information, see the documentation. The value of the `dump-logs` key controls what, if any, log file content is sent -('dumped') to the standard error output stream of the console at the end of the -build. Possible values are: +('dumped') to the standard error stream of the console at the end of the build. +Possible values are: ~~~yaml dump-logs: none # don't dump the content of any log files @@ -810,8 +810,8 @@ At the command line, `--no-dump-logs` is equivalent to `dump-logs: none` and If GHC reports an error during the build and a log file is created, that build output will be included in the log file. Stack will also report errors during -building to the standard error output stream. That stream can be piped to a -file. For example, for a file named `stderr.log`: +building to the standard error stream. That stream can be piped to a file. For +example, for a file named `stderr.log`: ~~~text stack --no-dump-logs --color always build --no-interleaved-output 2> stderr.log diff --git a/src/Stack/ConfigCmd.hs b/src/Stack/ConfigCmd.hs index f559811e80..7bcabe47ab 100644 --- a/src/Stack/ConfigCmd.hs +++ b/src/Stack/ConfigCmd.hs @@ -364,4 +364,4 @@ cfgCmdEnv es = do encodeUtf8Builder key <> ";\n" escape '\'' = "'\"'\"'" escape c = T.singleton c - hPutBuilder stdout $ Map.foldMapWithKey toLine actions + putBuilder $ Map.foldMapWithKey toLine actions diff --git a/src/Stack/IDE.hs b/src/Stack/IDE.hs index fcf3e29646..72ce78f2a0 100644 --- a/src/Stack/IDE.hs +++ b/src/Stack/IDE.hs @@ -29,13 +29,13 @@ import Stack.Types.SourceMap ( ProjectPackage (..), SMWanted (..), ppComponentsMaybe ) import System.IO ( putStrLn ) --- Type representing output channel choices for the @stack ide packages@ and +-- Type representing output stream choices for the @stack ide packages@ and -- @stack ide targets@ commands. data OutputStream = OutputLogInfo - -- ^ To the same output channel as other log information. + -- ^ To the same output stream as other log information. | OutputStdout - -- ^ To the standard output channel. + -- ^ To the standard output stream. -- Type representing output choices for the @stack ide packages@ command. data ListPackagesCmd diff --git a/src/Stack/Prelude.hs b/src/Stack/Prelude.hs index 0a99b6c356..dd750fdc59 100644 --- a/src/Stack/Prelude.hs +++ b/src/Stack/Prelude.hs @@ -23,6 +23,8 @@ module Stack.Prelude , bugReport , bugPrettyReport , blankLine + , putUtf8Builder + , putBuilder , ppException , prettyThrowIO , prettyThrowM @@ -46,6 +48,7 @@ module Stack.Prelude , bulletedList , debugBracket , defaultStyles + , displayWithColor , encloseSep , fill , fillSep @@ -104,14 +107,15 @@ import RIO.File as X hiding ( writeBinaryFileAtomic ) import RIO.PrettyPrint ( HasStylesUpdate (..), HasTerm (..), Pretty (..), Style (..) , StyleDoc, (<+>), align, blankLine, bulletedList - , debugBracket, encloseSep, fill, fillSep, flow, hang, hcat - , hsep, indent, line, logLevelToStyle, mkNarrativeList - , parens, prettyDebug, prettyDebugL, prettyError - , prettyErrorL, prettyGeneric, prettyInfo, prettyInfoL - , prettyInfoS, prettyNote, prettyNoteL, prettyNoteS - , prettyWarn, prettyWarnL, prettyWarnNoIndent, prettyWarnS - , punctuate, sep, softbreak, softline, spacedBulletedList - , string, style, stylesUpdateL, useColorL, vsep + , debugBracket, displayWithColor, encloseSep, fill, fillSep + , flow, hang, hcat, hsep, indent, line, logLevelToStyle + , mkNarrativeList, parens, prettyDebug, prettyDebugL + , prettyError, prettyErrorL, prettyGeneric, prettyInfo + , prettyInfoL, prettyInfoS, prettyNote, prettyNoteL + , prettyNoteS, prettyWarn, prettyWarnL, prettyWarnNoIndent + , prettyWarnS, punctuate, sep, softbreak, softline + , spacedBulletedList, string, style, stylesUpdateL, useColorL + , vsep ) import RIO.PrettyPrint.DefaultStyles (defaultStyles) import RIO.PrettyPrint.PrettyException @@ -350,3 +354,11 @@ bugRequest = "Please report this bug at Stack's repository." -- | Maybe cons. mcons :: Maybe a -> [a] -> [a] mcons ma as = maybe as (:as) ma + +-- | Write a 'Utf8Builder' to the standard output stream. +putUtf8Builder :: MonadIO m => Utf8Builder -> m () +putUtf8Builder = putBuilder . getUtf8Builder + +-- | Write a 'Builder' to the standard output stream. +putBuilder :: MonadIO m => Builder -> m () +putBuilder = hPutBuilder stdout diff --git a/src/Stack/Templates.hs b/src/Stack/Templates.hs index f41d38e85d..352221f290 100644 --- a/src/Stack/Templates.hs +++ b/src/Stack/Templates.hs @@ -8,7 +8,7 @@ module Stack.Templates ) where import qualified Data.ByteString.Lazy as LB -import qualified Data.Text as T +import qualified Data.Text.IO as T import Network.HTTP.StackClient ( HttpException (..), getResponseBody, httpLbs, parseUrlThrow , setGitHubHeaders @@ -69,7 +69,7 @@ templatesHelp = do (prettyThrowM . DownloadTemplatesHelpFailed) case decodeUtf8' $ LB.toStrict $ getResponseBody resp of Left err -> prettyThrowM $ TemplatesHelpEncodingInvalid url err - Right txt -> prettyInfo (string $ T.unpack txt) + Right txt -> liftIO $ T.putStrLn txt -- | Default web URL to get the `stack templates` help output. defaultTemplatesHelpUrl :: String diff --git a/src/Stack/Uninstall.hs b/src/Stack/Uninstall.hs index b4f114c3bd..c4dbdfd1b4 100644 --- a/src/Stack/Uninstall.hs +++ b/src/Stack/Uninstall.hs @@ -6,14 +6,14 @@ module Stack.Uninstall ( uninstallCmd ) where -import Stack.Constants ( osIsWindows ) -import Stack.Prelude -import Stack.Runners ( ShouldReexec (..), withConfig ) -import Stack.Types.Config - ( configL, configLocalBin, configLocalProgramsBase - , stackGlobalConfigL, stackRootL - ) -import Stack.Types.Runner ( Runner ) +import Stack.Constants ( osIsWindows ) +import Stack.Prelude +import Stack.Runners ( ShouldReexec (..), withConfig ) +import Stack.Types.Config + ( configL, configLocalBin, configLocalProgramsBase + , stackGlobalConfigL, stackRootL + ) +import Stack.Types.Runner ( Runner ) -- | Function underlying the @stack uninstall@ command. Display help for the -- command. @@ -28,8 +28,8 @@ uninstallCmd () = withConfig NoReexec $ do globalConfig' = toStyleDoc globalConfig programsDir' = toStyleDoc programsDir localBinDir' = toStyleDoc localBinDir - prettyInfo $ - vsep + putUtf8Builder =<< displayWithColor + ( vsep [ flow "To uninstall Stack, it should be sufficient to delete:" , hang 4 $ fillSep [ flow "(1) the directory containing Stack's tools" @@ -59,26 +59,27 @@ uninstallCmd () = withConfig NoReexec $ do , flow "directories in any Haskell projects that you have built." ] ] - <> blankLine - <> vsep - [ fillSep - [ flow "To uninstall completely a Stack-supplied tool (such as \ - \GHC or, on Windows, MSYS2), delete from Stack's tools \ - \directory" - , parens programsDir' <> ":" - ] - , hang 4 $ fillSep - [ flow "(1) the tool's subdirectory;" - ] - , hang 4 $ fillSep - [ flow "(2) the tool's archive file" - , parens (style File ".tar.xz") <> "; and" - ] - , hang 4 $ fillSep - [ flow "(3) the file marking that the tool is installed" - , parens (style File ".installed") <> "." - ] - ] + <> blankLine + <> vsep + [ fillSep + [ flow "To uninstall completely a Stack-supplied tool (such as \ + \GHC or, on Windows, MSYS2), delete from Stack's tools \ + \directory" + , parens programsDir' <> ":" + ] + , hang 4 $ fillSep + [ flow "(1) the tool's subdirectory;" + ] + , hang 4 $ fillSep + [ flow "(2) the tool's archive file" + , parens (style File ".tar.xz") <> "; and" + ] + , hang 4 $ fillSep + [ flow "(3) the file marking that the tool is installed" + , parens (style File ".installed") <> "." + ] + ] + ) where styleShell = style Shell howToFindStack