Skip to content

Commit cfcd04c

Browse files
authored
Merge pull request #5824 from mpilgrem/fix5312
Fix #5312 Better help for `stack ls snapshots local`
2 parents bac18fe + b8ea791 commit cfcd04c

File tree

2 files changed

+29
-26
lines changed

2 files changed

+29
-26
lines changed

ChangeLog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ Bug fixes:
5555
* Fixed logic in `get_isa()` in `get-stack.sh` to exclude systems that don't
5656
have x86 in their `uname -m` output. See
5757
[5792](https://github.com/commercialhaskell/stack/issues/5792).
58+
* Fixed output of `stack ls snapshots local` on Windows, to behave like that on
59+
Unix-like operating systems.
5860

5961
## v2.7.5
6062

src/Stack/Ls.hs

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
module Stack.Ls
77
( lsCmd
88
, lsParser
9-
, listDependenciesCmd
109
) where
1110

1211
import Control.Exception (throw)
@@ -30,6 +29,7 @@ import RIO.PrettyPrint (useColorL)
3029
import RIO.PrettyPrint.DefaultStyles (defaultStyles)
3130
import RIO.PrettyPrint.Types (StyleSpec)
3231
import RIO.PrettyPrint.StylesUpdate (StylesUpdate (..), stylesUpdateL)
32+
import Stack.Constants (osIsWindows)
3333
import Stack.Dot
3434
import Stack.Runners
3535
import Stack.Options.DotParser (listDepsOptsParser)
@@ -132,12 +132,10 @@ lsViewSnapCmd =
132132
OA.help "Only show nightly snapshots")
133133

134134
lsSnapCmd :: OA.Mod OA.CommandFields LsCmds
135-
lsSnapCmd =
136-
OA.command
137-
"snapshots"
138-
(OA.info
139-
lsCmdOptsParser
140-
(OA.progDesc "View local snapshot (default option)"))
135+
lsSnapCmd = OA.command "snapshots" $
136+
OA.info lsCmdOptsParser $
137+
OA.progDesc "View snapshots (local by default)"
138+
<> OA.footer localSnapshotMsg
141139

142140
lsDepsCmd :: OA.Mod OA.CommandFields LsCmds
143141
lsDepsCmd =
@@ -254,7 +252,10 @@ handleLocal :: LsCmdOpts -> RIO Runner ()
254252
handleLocal lsOpts = do
255253
(instRoot :: Path Abs Dir) <- withConfig YesReexec $ withDefaultEnvConfig installationRootDeps
256254
isStdoutTerminal <- view terminalL
257-
let snapRootDir = parent $ parent instRoot
255+
let parentInstRoot = parent instRoot
256+
snapRootDir
257+
| osIsWindows = parentInstRoot
258+
| otherwise = parent parentInstRoot
258259
snapData' <- liftIO $ listDirectory $ toFilePath snapRootDir
259260
let snapData = L.sort snapData'
260261
case lsView lsOpts of
@@ -307,30 +308,30 @@ lsCmd lsOpts =
307308
case soptViewType of
308309
Local -> handleLocal lsOpts
309310
Remote -> handleRemote lsOpts
310-
LsDependencies depOpts -> listDependenciesCmd False depOpts
311+
LsDependencies depOpts -> listDependencies depOpts
311312
LsStyles stylesOpts -> withConfig NoReexec $ listStylesCmd stylesOpts
312313
LsTools toolsOpts -> withConfig NoReexec $ listToolsCmd toolsOpts
313314

314-
-- | List the dependencies
315-
listDependenciesCmd :: Bool -> ListDepsOpts -> RIO Runner ()
316-
listDependenciesCmd deprecated opts = do
317-
when
318-
deprecated
319-
(logWarn
320-
"DEPRECATED: Use ls dependencies instead. Will be removed in next major version.")
321-
listDependencies opts
322-
323315
lsViewLocalCmd :: OA.Mod OA.CommandFields LsView
324-
lsViewLocalCmd =
325-
OA.command
326-
"local"
327-
(OA.info (pure Local) (OA.progDesc "View local snapshot"))
316+
lsViewLocalCmd = OA.command "local" $
317+
OA.info (pure Local) $
318+
OA.progDesc "View local snapshots"
319+
<> OA.footer localSnapshotMsg
328320

329321
lsViewRemoteCmd :: OA.Mod OA.CommandFields LsView
330-
lsViewRemoteCmd =
331-
OA.command
332-
"remote"
333-
(OA.info (pure Remote) (OA.progDesc "View remote snapshot"))
322+
lsViewRemoteCmd = OA.command "remote" $
323+
OA.info (pure Remote) $
324+
OA.progDesc "View remote snapshots"
325+
<> OA.footer pagerMsg
326+
327+
pagerMsg :: String
328+
pagerMsg =
329+
"On a terminal, uses a pager, if one is available. Respects the PAGER \
330+
\environment variable (subject to that, prefers pager 'less' to 'more')."
331+
332+
localSnapshotMsg :: String
333+
localSnapshotMsg =
334+
"A local snapshot is identified by a hash code. " <> pagerMsg
334335

335336
-- | List stack's output styles
336337
listStylesCmd :: ListStylesOpts -> RIO Config ()

0 commit comments

Comments
 (0)