Skip to content

Commit e978207

Browse files
committed
Pretty print the JSON dumps.
1 parent d1fc7a6 commit e978207

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

package.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dependencies:
5252
- base >= 4.16.3.0 && < 5
5353
- Cabal >= 3.6.3.0
5454
- aeson >= 2.0.3.0
55+
- aeson-pretty
5556
- annotated-wl-pprint
5657
- ansi-terminal
5758
- array

src/Stack/ConfigCmd.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import Stack.Prelude
4848
import Data.Coerce (coerce)
4949
import Pantry.Internal.AesonExtended
5050
(ToJSON(..), FromJSON, (.=), WithJSONWarnings (WithJSONWarnings), object)
51-
import qualified Data.Aeson as Aeson
51+
import Data.Aeson.Encode.Pretty (encodePretty)
5252
import qualified Data.Aeson.Key as Key
5353
import Data.Aeson.KeyMap (KeyMap)
5454
import qualified Data.Aeson.KeyMap as KeyMap
@@ -128,18 +128,18 @@ configCmdSetScope (ConfigCmdSetSystemGhc scope _) = scope
128128
configCmdSetScope (ConfigCmdSetInstallGhc scope _) = scope
129129

130130
encodeDumpProject :: RawYaml -> ConfigDumpFormat -> Project -> ByteString
131-
encodeDumpProject _ ConfigDumpJson = toStrictBytes . Aeson.encode
131+
encodeDumpProject _ ConfigDumpJson = toStrictBytes . encodePretty
132132
encodeDumpProject rawConfig ConfigDumpYaml = \p -> let e = Yaml.encode p in
133133
Yaml.decodeEither' e & either (const e) (\(d :: KeyMap Yaml.Value) ->
134134
either (const e) encodeUtf8 (cfgRedress rawConfig d ""))
135135

136136
encodeDumpStackBy :: ToJSON a => (Config -> a) -> ConfigCmdDumpStack -> (Config -> ByteString)
137137
encodeDumpStackBy f (ConfigCmdDumpStack _ ConfigDumpYaml) = Yaml.encode . f
138-
encodeDumpStackBy f (ConfigCmdDumpStack _ ConfigDumpJson) = toStrictBytes . Aeson.encode . f
138+
encodeDumpStackBy f (ConfigCmdDumpStack _ ConfigDumpJson) = toStrictBytes . encodePretty . f
139139

140140
encodeDumpStack :: ConfigDumpFormat -> (DumpStack -> ByteString)
141141
encodeDumpStack ConfigDumpYaml = Yaml.encode
142-
encodeDumpStack ConfigDumpJson = toStrictBytes . Aeson.encode
142+
encodeDumpStack ConfigDumpJson = toStrictBytes . encodePretty
143143

144144
cfgReadProject :: (HasConfig env, HasLogFunc env) => CommandScope -> RIO env (Maybe Project)
145145
cfgReadProject scope = do

stack.cabal

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ library
229229
build-depends:
230230
Cabal >=3.6.3.0
231231
, aeson >=2.0.3.0
232+
, aeson-pretty
232233
, annotated-wl-pprint
233234
, ansi-terminal
234235
, array
@@ -353,6 +354,7 @@ executable stack
353354
build-depends:
354355
Cabal >=3.6.3.0
355356
, aeson >=2.0.3.0
357+
, aeson-pretty
356358
, annotated-wl-pprint
357359
, ansi-terminal
358360
, array
@@ -476,6 +478,7 @@ executable stack-integration-test
476478
build-depends:
477479
Cabal >=3.6.3.0
478480
, aeson >=2.0.3.0
481+
, aeson-pretty
479482
, annotated-wl-pprint
480483
, ansi-terminal
481484
, array
@@ -607,6 +610,7 @@ test-suite stack-test
607610
Cabal >=3.6.3.0
608611
, QuickCheck
609612
, aeson >=2.0.3.0
613+
, aeson-pretty
610614
, annotated-wl-pprint
611615
, ansi-terminal
612616
, array

0 commit comments

Comments
 (0)