@@ -15,6 +15,7 @@ import Terminal.Init
15
15
import Terminal.Run
16
16
import Terminal.Help
17
17
import Terminal.Repl
18
+ import Terminal.Report exposing (Report)
18
19
import Compiler.Backend
19
20
import Compiler.PackageName as PackageName exposing (PackageName)
20
21
import Compiler.Paths
@@ -293,7 +294,7 @@ update msg model =
293
294
|> Task.onError
294
295
(\error ->
295
296
Terminal.Run.prettifyError error
296
- |> Terminal.Help.prettyPrint { useColor = model.useColor }
297
+ |> Terminal.Report.toString (Terminal.Report.Terminal { useColor = model.useColor })
297
298
|> Stream.Log.line model.stderr
298
299
|> Task.map (\_ -> Task.execute <| Node.exitWithCode 1)
299
300
)
@@ -351,6 +352,10 @@ parseUserArgs model compilerPath =
351
352
endWithErrorString stringErr =
352
353
Stream.Log.string model.stderr stringErr
353
354
|> Task.map (\_ -> Task.execute <| Node.exitWithCode 1)
355
+
356
+ endWithErrorReport outputType report =
357
+ Terminal.Report.toString outputType report
358
+ |> endWithErrorString
354
359
in
355
360
when CLI.Parser.run model.args CliParser.parser is
356
361
CLI.Parser.UnknownCommand commandName ->
@@ -410,7 +415,7 @@ parseUserArgs model compilerPath =
410
415
}
411
416
|> Task.map (\_ -> Cmd.none)
412
417
|> Task.mapError Terminal.Init.prettifyError
413
- |> Task.onError endWithError
418
+ |> Task.onError (endWithErrorReport (Terminal.Report.Terminal printOpts))
414
419
|> Task.perform RunCmd
415
420
416
421
CliParser.Repl flags ->
@@ -467,7 +472,7 @@ parseUserArgs model compilerPath =
467
472
, onComplete = CompilerRan
468
473
}
469
474
)
470
- |> Task.onError endWithError
475
+ |> Task.onError (endWithErrorReport (Terminal.Report.Terminal printOpts))
471
476
|> Task.perform RunCmd
472
477
473
478
CliParser.Make flags ->
@@ -482,6 +487,14 @@ parseUserArgs model compilerPath =
482
487
483
488
_ ->
484
489
Task.succeed model.stdout
490
+
491
+ reportType =
492
+ when flags.report is
493
+ Just {} ->
494
+ Terminal.Report.Json
495
+
496
+ Nothing ->
497
+ Terminal.Report.Terminal printOpts
485
498
in
486
499
determineOutputStreamForResolve
487
500
|> Task.andThen (\output -> resolveProject { model | stdout = output })
@@ -508,7 +521,7 @@ parseUserArgs model compilerPath =
508
521
, onComplete = CompilerRan
509
522
}
510
523
)
511
- |> Task.onError endWithError
524
+ |> Task.onError (endWithErrorReport reportType)
512
525
|> Task.perform RunCmd
513
526
514
527
CliParser.Run opts ->
@@ -543,7 +556,7 @@ parseUserArgs model compilerPath =
543
556
)
544
557
}
545
558
|> Task.mapError Terminal.Run.prettifyError
546
- |> Task.onError endWithError
559
+ |> Task.onError (endWithErrorReport (Terminal.Report.Terminal printOpts))
547
560
|> Task.perform RunCmd
548
561
549
562
CliParser.Docs flags ->
@@ -558,6 +571,14 @@ parseUserArgs model compilerPath =
558
571
559
572
_ ->
560
573
Task.succeed model.stdout
574
+
575
+ reportType =
576
+ when flags.report is
577
+ Just {} ->
578
+ Terminal.Report.Json
579
+
580
+ Nothing ->
581
+ Terminal.Report.Terminal printOpts
561
582
in
562
583
determineOutputStreamForResolve
563
584
|> Task.andThen (\output -> resolveProject { model | stdout = output })
@@ -581,18 +602,18 @@ parseUserArgs model compilerPath =
581
602
, onComplete = CompilerRan
582
603
}
583
604
)
584
- |> Task.onError endWithError
605
+ |> Task.onError (endWithErrorReport reportType)
585
606
|> Task.perform RunCmd
586
607
587
608
CliParser.PackageInstall Nothing ->
588
609
resolveProject model
589
610
|> Task.andThen
590
611
(\res ->
591
612
Terminal.PackageInstall.cleanPackageDirectory model.fsPermission res
592
- |> Task.mapError (\_ -> PP .empty)
613
+ |> Task.mapError (\_ -> Terminal.Report .empty)
593
614
)
594
615
|> Task.map (\_ -> Cmd.none)
595
- |> Task.onError endWithError
616
+ |> Task.onError (endWithErrorReport (Terminal.Report.Terminal printOpts))
596
617
|> Task.perform RunCmd
597
618
598
619
CliParser.PackageInstall (Just requestedPackage) ->
@@ -615,7 +636,7 @@ parseUserArgs model compilerPath =
615
636
|> Task.mapError Terminal.PackageInstall.prettifyAddPackageError
616
637
)
617
638
|> Task.map (\_ -> Cmd.none)
618
- |> Task.onError endWithError
639
+ |> Task.onError (endWithErrorReport (Terminal.Report.Terminal printOpts))
619
640
|> Task.perform RunCmd
620
641
621
642
CliParser.PackageUninstall packageName ->
@@ -638,11 +659,11 @@ parseUserArgs model compilerPath =
638
659
|> Task.andThen
639
660
(\res ->
640
661
Terminal.PackageInstall.cleanPackageDirectory model.fsPermission res
641
- |> Task.mapError (\_ -> PP .empty)
662
+ |> Task.mapError (\_ -> Terminal.Report .empty)
642
663
)
643
664
)
644
665
|> Task.map (\_ -> Cmd.none)
645
- |> Task.onError endWithError
666
+ |> Task.onError (endWithErrorReport (Terminal.Report.Terminal printOpts))
646
667
|> Task.perform RunCmd
647
668
648
669
CliParser.PackageOutdated ->
@@ -662,7 +683,7 @@ parseUserArgs model compilerPath =
662
683
|> Task.mapError Terminal.PackageOutdated.prettifyError
663
684
)
664
685
|> Task.map (\_ -> Cmd.none)
665
- |> Task.onError endWithError
686
+ |> Task.onError (endWithErrorReport (Terminal.Report.Terminal printOpts))
666
687
|> Task.perform RunCmd
667
688
668
689
CliParser.PackageValidate ->
@@ -695,7 +716,7 @@ parseUserArgs model compilerPath =
695
716
, onComplete = CompilerRan
696
717
}
697
718
)
698
- |> Task.onError endWithError
719
+ |> Task.onError (endWithErrorReport (Terminal.Report.Terminal printOpts))
699
720
|> Task.perform RunCmd
700
721
701
722
CliParser.PackageBump ->
@@ -728,7 +749,7 @@ parseUserArgs model compilerPath =
728
749
, onComplete = CompilerRan
729
750
}
730
751
)
731
- |> Task.onError endWithError
752
+ |> Task.onError (endWithErrorReport (Terminal.Report.Terminal printOpts))
732
753
|> Task.perform RunCmd
733
754
734
755
CliParser.PackageDiff args ->
@@ -818,7 +839,7 @@ parseUserArgs model compilerPath =
818
839
, onComplete = CompilerRan
819
840
}
820
841
)
821
- |> Task.onError endWithError
842
+ |> Task.onError (endWithErrorReport (Terminal.Report.Terminal printOpts))
822
843
|> Task.perform RunCmd
823
844
824
845
CliParser.Paths opts ->
@@ -836,7 +857,7 @@ parseUserArgs model compilerPath =
836
857
|> Task.perform RunCmd
837
858
838
859
839
- resolveProject : Model -> Task PP.Document Terminal.PackageInstall.PackageResolution
860
+ resolveProject : Model -> Task Report Terminal.PackageInstall.PackageResolution
840
861
resolveProject model =
841
862
Terminal.PackageInstall.readProjectOutline model.fsPermission
842
863
|> Task.mapError Terminal.PackageInstall.prettifyProjectOutlineError
@@ -858,7 +879,7 @@ resolveProject model =
858
879
859
880
860
881
-- TODO: Move to gren-lang/compiler-node
861
- verifyMakeFlags : FileSystem.Permission -> Array ModuleName -> Maybe Compiler.Backend.MakeOutput -> Terminal.PackageInstall.PackageResolution -> Task PP.Document Terminal.PackageInstall.PackageResolution
882
+ verifyMakeFlags : FileSystem.Permission -> Array ModuleName -> Maybe Compiler.Backend.MakeOutput -> Terminal.PackageInstall.PackageResolution -> Task Report Terminal.PackageInstall.PackageResolution
862
883
verifyMakeFlags fsPermission entryPoints maybeOutput resolution =
863
884
let
864
885
maybeOutputPath =
@@ -908,7 +929,7 @@ verifyMakeFlags fsPermission entryPoints maybeOutput resolution =
908
929
909
930
else
910
931
Task.fail <|
911
- Terminal.Help.report
932
+ Terminal.Report.create
912
933
"CANNOT ACCESS OUTPUT PATH"
913
934
(Just path)
914
935
(PP.verticalBlock
@@ -928,7 +949,7 @@ verifyMakeFlags fsPermission entryPoints maybeOutput resolution =
928
949
929
950
Just metadata ->
930
951
if metadata.entityType == FileSystem.Directory then
931
- Terminal.Help.report
952
+ Terminal.Report.create
932
953
"OUTPUT PATH IS A DIRECTORY"
933
954
(Just path)
934
955
(PP.verticalBlock
@@ -955,7 +976,7 @@ verifyMakeFlags fsPermission entryPoints maybeOutput resolution =
955
976
956
977
Just { value = moduleName } ->
957
978
Task.fail <|
958
- Terminal.Help.report
979
+ Terminal.Report.create
959
980
"MODULE DOES NOT EXIST"
960
981
Nothing
961
982
(PP.verticalBlock
0 commit comments