4
4
5
5
import Prelude
6
6
7
- import Data.Function ( (&) )
7
+ import Data.Bool ( bool )
8
8
import System.Environment (lookupEnv )
9
9
import GHC.Stack (HasCallStack )
10
10
-- Package: aeson.
@@ -79,17 +79,19 @@ data Cli =
79
79
NamesNoEra
80
80
| NamesCloudNoEra
81
81
| Names
82
- | All
83
- | ByName PrettyPrint String
82
+ | All [ CliOptions ]
83
+ | ByName [ CliOptions ] String
84
84
| LibMK
85
85
| NodeSpecs FilePath FilePath
86
86
| EpochTimeline Integer
87
87
| ToJson String
88
88
| FromJson String
89
89
90
- data PrettyPrint =
91
- PrettyPrint
92
- | SingleLine
90
+ data CliOptions =
91
+ OptPrettyPrint
92
+ | OptWithEra
93
+ | OptWithPlayground
94
+ deriving Eq
93
95
94
96
--------------------------------------------------------------------------------
95
97
@@ -106,31 +108,19 @@ toMap maybeObj ps = Map.fromList $ map
106
108
)
107
109
ps
108
110
109
- -- All profiles are created/defined in the Conway era.
110
- addEras :: Map. Map String Types. Profile -> Map. Map String Types. Profile
111
- addEras = foldMap
112
- (\ profile -> Map. fromList $
113
- let
114
- -- TODO: Profiles properties other than the "name" and "era" of
115
- -- type string are the only thing that change ??? Remove the
116
- -- concept of eras from the profile definitions and make it a
117
- -- workbench-level feature (???).
118
- addEra p era suffix =
119
- let name = Types. name p
120
- newName = name ++ " -" ++ suffix
121
- in (newName, p {Types. name = newName, Types. era = era})
122
- in
123
- [ addEra profile Types. Allegra " alra"
124
- , addEra profile Types. Shelley " shey"
125
- , addEra profile Types. Mary " mary"
126
- , addEra profile Types. Alonzo " alzo"
127
- , addEra profile Types. Babbage " bage"
128
- , addEra profile Types. Conway " coay"
129
- ]
130
- )
131
-
132
111
--------------------------------------------------------------------------------
133
112
113
+ encoder :: Aeson. ToJSON a => [CliOptions ] -> a -> BSL8. ByteString
114
+ encoder opts
115
+ | OptPrettyPrint `elem` opts = Aeson. encodePretty' prettyConf
116
+ | otherwise = Aeson. encode
117
+ where
118
+ prettyConf = defConfig
119
+ { confCompare = compare
120
+ , confTrailingNewline = True
121
+ , confIndent = Spaces 2
122
+ }
123
+
134
124
main :: IO ()
135
125
main = do
136
126
cli <- getOpts
@@ -142,24 +132,24 @@ main = do
142
132
-- Print all profile names (applies overlays!!!!!).
143
133
Names -> do
144
134
maybeObj <- lookupOverlay -- Ignored by `NamesNoEra` and `NamesCloudNoEra`.
145
- BSL8. putStrLn $ Aeson. encode $ Map. keys $ addEras $ toMap maybeObj allProfiles
135
+ BSL8. putStrLn $ Aeson. encode $ Map. keys $ Profile. addEras $ toMap maybeObj allProfiles
146
136
-- Print a map with all profiles, with an optional overlay.
147
- All -> do
137
+ All cliOptions -> do
138
+ let
139
+ targetProfiles = if OptWithPlayground `elem` cliOptions then allProfiles else performanceAndTracingProfiles
140
+ enc = encoder cliOptions
141
+ withEraSuffs = OptWithEra `elem` cliOptions
148
142
maybeObj <- lookupOverlay -- Ignored by `NamesNoEra` and `NamesCloudNoEra`.
149
- BSL8. putStrLn $ Aeson. encode $ addEras $ toMap maybeObj allProfiles
143
+ BSL8. putStrLn $ enc $ bool id Profile. addEras withEraSuffs $ toMap maybeObj targetProfiles
150
144
-- Print a single profiles, with an optional overlay.
151
- ( ByName prettyPrint profileName) -> do
145
+ ByName cliOptions profileName -> do
152
146
maybeObj <- lookupOverlay -- Ignored by `NamesNoEra` and `NamesCloudNoEra`.
153
- let profiles = addEras $ toMap maybeObj allProfiles
147
+ let
148
+ enc = encoder cliOptions
149
+ profiles = Profile. addEras $ toMap maybeObj allProfiles
154
150
case Map. lookup profileName profiles of
155
- Nothing -> error $ " No profile named \" " ++ profileName ++ " \" "
156
- (Just profile) ->
157
- let
158
- prettyConf = defConfig { confCompare = compare , confTrailingNewline = True }
159
- aeson = profile & case prettyPrint of
160
- PrettyPrint -> Aeson. encodePretty' prettyConf
161
- SingleLine -> Aeson. encode
162
- in BSL8. putStrLn aeson
151
+ Nothing -> error $ " No profile named \" " ++ profileName ++ " \" "
152
+ Just profile -> BSL8. putStrLn $ enc profile
163
153
LibMK -> do
164
154
mapM_ putStrLn libMk
165
155
(NodeSpecs profilePath topologyPath) -> do
@@ -229,19 +219,31 @@ cliParser = OA.hsubparser $
229
219
<>
230
220
OA. command " all"
231
221
(OA. info
232
- (pure All )
222
+ (pure $ All [ OptWithEra , OptWithPlayground ] )
233
223
(OA. fullDesc <> OA. header " all" <> OA. progDesc " Create all profiles" )
234
224
)
225
+ <>
226
+ OA. command " all-noera"
227
+ (OA. info
228
+ (pure $ All [OptWithPlayground ])
229
+ (OA. fullDesc <> OA. header " all-noera" <> OA. progDesc " Create all profiles (no era suffix)" )
230
+ )
231
+ <>
232
+ OA. command " allpt-noera"
233
+ (OA. info
234
+ (pure $ All [OptPrettyPrint ])
235
+ (OA. fullDesc <> OA. header " allpt-noera" <> OA. progDesc " Create P&T profiles (no era suffix)" )
236
+ )
235
237
<>
236
238
OA. command " by-name"
237
239
(OA. info
238
- (ByName SingleLine <$> OA. argument OA. str (OA. metavar " PROFILE-NAME" ))
240
+ (ByName [] <$> OA. argument OA. str (OA. metavar " PROFILE-NAME" ))
239
241
(OA. fullDesc <> OA. header " by-name" <> OA. progDesc " Create profile" )
240
242
)
241
243
<>
242
244
OA. command " by-name-pretty"
243
245
(OA. info
244
- (ByName PrettyPrint <$> OA. argument OA. str (OA. metavar " PROFILE-NAME" ))
246
+ (ByName [ OptPrettyPrint ] <$> OA. argument OA. str (OA. metavar " PROFILE-NAME" ))
245
247
(OA. fullDesc <> OA. header " by-name-pretty" <> OA. progDesc " Create profile (pretty-printed)" )
246
248
)
247
249
<>
0 commit comments