on 64dcd7e help sign in
72 lines 2.1 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Exit.Diff
3 ( Exit(..)
4 , toReport
5 )
6 where
9import qualified Data.List as List
11import qualified Elm.Package as Pkg
12import qualified Reporting.Doc as D
13import qualified Reporting.Exit.Help as Help
17-- EXITS
20data Exit
21 = Application
22 | Unpublished
23 | UnknownPackage Pkg.Name [Pkg.Name]
24 | UnknownVersion Pkg.Name Pkg.Version [Pkg.Version]
28-- TO DOC
31toReport :: Exit -> Help.Report
32toReport exit =
33 case exit of
34 Application ->
35 Help.report "CANNOT DIFF APPLICATIONS" Nothing
36 "I cannot perform diffs on applications, only packages! If you are\
37 \ just curious to see a diff, try running this command:"
38 [ D.indent 4 $ D.green $ "elm diff elm/html 5.1.1 6.0.0"
39 ]
41 Unpublished ->
42 Help.report "UNPUBLISHED" Nothing
43 "This package is not published yet. There is nothing to diff against!"
44 []
46 UnknownPackage pkg suggestions ->
47 Help.report "UNKNOWN PACKAGE" Nothing
48 ( "I cannot find a package called:"
49 )
50 [ D.indent 4 $ D.red $ D.fromText $ Pkg.toText pkg
51 , "Maybe you want one of these instead?"
52 , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromText . Pkg.toText) suggestions
53 , "But check <https://package.elm-lang.org> to see all possibilities!"
54 ]
56 UnknownVersion _pkg vsn realVersions ->
57 Help.docReport "UNKNOWN VERSION" Nothing
58 ( D.fillSep $
59 [ "Version", D.red (D.fromText (Pkg.versionToText vsn))
60 , "has", "never", "been", "published,", "so", "I"
61 , "cannot", "diff", "against", "it."
62 ]
63 )
64 [ "Here are all the versions that HAVE been published:"
65 , D.indent 4 $ D.dullyellow $ D.vcat $
66 let
67 sameMajor v1 v2 = Pkg._major v1 == Pkg._major v2
68 mkRow vsns = D.hsep $ map (D.fromText . Pkg.versionToText) vsns
69 in
70 map mkRow $ List.groupBy sameMajor (List.sort realVersions)
71 , "Want one of those instead?"
72 ]