on efe80bc help sign in
73 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 Elm.Version as V
13import qualified Reporting.Doc as D
14import qualified Reporting.Exit.Help as Help
18-- EXITS
21data Exit
22 = Application
23 | Unpublished
24 | UnknownPackage Pkg.Name [Pkg.Name]
25 | UnknownVersion Pkg.Name V.Version [V.Version]
29-- TO DOC
32toReport :: Exit -> Help.Report
33toReport exit =
34 case exit of
35 Application ->
36 Help.report "CANNOT DIFF APPLICATIONS" Nothing
37 "I cannot perform diffs on applications, only packages! If you are\
38 \ just curious to see a diff, try running this command:"
39 [ D.indent 4 $ D.green $ "elm diff elm/html 5.1.1 6.0.0"
40 ]
42 Unpublished ->
43 Help.report "UNPUBLISHED" Nothing
44 "This package is not published yet. There is nothing to diff against!"
45 []
47 UnknownPackage pkg suggestions ->
48 Help.report "UNKNOWN PACKAGE" Nothing
49 ( "I cannot find a package called:"
50 )
51 [ D.indent 4 $ D.red $ D.fromUtf8 $ Pkg.toString pkg
52 , "Maybe you want one of these instead?"
53 , D.indent 4 $ D.dullyellow $ D.vcat $ map (D.fromUtf8 . Pkg.toString) suggestions
54 , "But check <https://package.elm-lang.org> to see all possibilities!"
55 ]
57 UnknownVersion _pkg vsn realVersions ->
58 Help.docReport "UNKNOWN VERSION" Nothing
59 ( D.fillSep $
60 [ "Version", D.red (D.fromUtf8 (V.toString vsn))
61 , "has", "never", "been", "published,", "so", "I"
62 , "cannot", "diff", "against", "it."
63 ]
64 )
65 [ "Here are all the versions that HAVE been published:"
66 , D.indent 4 $ D.dullyellow $ D.vcat $
67 let
68 sameMajor v1 v2 = V._major v1 == V._major v2
69 mkRow vsns = D.hsep $ map (D.fromUtf8 . V.toString) vsns
70 in
71 map mkRow $ List.groupBy sameMajor (List.sort realVersions)
72 , "Want one of those instead?"
73 ]