on bf2e5eb help sign in
66 lines 1.9 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 | UnknownPackage Pkg.Name [Pkg.Name]
23 | UnknownVersion Pkg.Name Pkg.Version [Pkg.Version]
27-- TO DOC
30toReport :: Exit -> Help.Report
31toReport exit =
32 case exit of
33 Application ->
34 Help.report "CANNOT DIFF APPLICATIONS" Nothing
35 "I cannot perform diffs on applications, only packages! If you are\
36 \ just curious to see a diff, try running this command:"
37 [ D.indent 4 $ D.green $ "elm diff elm-lang/html 5.1.1 6.0.0"
38 ]
40 UnknownPackage pkg suggestions ->
41 Help.report "UNKNOWN PACKAGE" Nothing
42 ( "I cannot find a package called:"
43 )
44 [ D.indent 4 $ D.red $ D.fromText $ Pkg.toText pkg
45 , "Maybe you want one of these instead?"
46 , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromText . Pkg.toText) suggestions
47 , "But check <https://package.elm-lang.org> to see all possibilities!"
48 ]
50 UnknownVersion _pkg vsn realVersions ->
51 Help.docReport "UNKNOWN VERSION" Nothing
52 ( D.fillSep $
53 [ "Version", D.red (D.fromText (Pkg.versionToText vsn))
54 , "has", "never", "been", "published,", "so", "I"
55 , "cannot", "diff", "against", "it."
56 ]
57 )
58 [ "Here are all the versions that HAVE been published:"
59 , D.indent 4 $ D.dullyellow $ D.vcat $
60 let
61 sameMajor v1 v2 = Pkg._major v1 == Pkg._major v2
62 mkRow vsns = D.hsep $ map (D.fromText . Pkg.versionToText) vsns
63 in
64 map mkRow $ List.groupBy sameMajor (List.sort realVersions)
65 , "Want one of those instead?"
66 ]