@@ -32,17 +32,22 @@ main :: IO ()
3232main = do
3333 do hSetBuffering stdout LineBuffering
3434 hSetBuffering stdin LineBuffering
35- ((inp, file, aslines, browse, markdown, pretty), () ) <-
35+ ((inp, file, inarray, aslines, browse, markdown, pretty), () ) <-
3636 simpleOptions
3737 " 0.0.0"
3838 " jl - JSON Lambda calculus"
3939 " Command-line language for querying and outputting JSON."
40- ((,,,,,) <$>
40+ ((,,,,,, ) <$>
4141 strArgument
4242 (metavar " CODE" <>
4343 help " JL code; supports completion of function names" <>
4444 completeWith (map (\ (Variable v) -> T. unpack v) (M. keys context))) <*>
4545 optional (strArgument (metavar " FILE" )) <*>
46+ flag
47+ False
48+ True
49+ (short ' a' <> long " array" <>
50+ help " Read each line of input as a single array" ) <*>
4651 flag
4752 False
4853 True
@@ -101,14 +106,21 @@ main = do
101106 case Aeson. decode bytes of
102107 Nothing -> hPutStr stderr " invalid input JSON"
103108 Just j -> handleJson pretty expr0 aslines j
104- Nothing -> process pretty expr0 aslines
109+ Nothing -> process pretty expr0 inarray aslines
105110 where
106- process pretty expr0 aslines =
111+ process pretty expr0 inarray aslines =
107112 CB. sourceHandle stdin $= CB. lines $= conduitParserEither Aeson. value $=
108- CL. mapM_
109- (either
110- (hPutStrLn stderr . errorMessage)
111- (handleJson pretty expr0 aslines . snd )) $$
113+ (if inarray
114+ then do
115+ es <-
116+ CL. mapM (either (error . errorMessage) (return . snd )) $=
117+ CL. consume
118+ liftIO
119+ (handleJson pretty expr0 aslines (Aeson. Array (V. fromList es)))
120+ else CL. mapM_
121+ (either
122+ (hPutStrLn stderr . errorMessage)
123+ (handleJson pretty expr0 aslines . snd ))) $$
112124 CL. sinkNull
113125
114126-- | Handle a JSON input, printing out one to many JSON values.
0 commit comments