on 2ce0625 help sign in
78 lines 2.4 kB history raw
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Diff
4 ( Error(..)
5 , toReport
6 )
7 where
9import qualified Data.List as List
10import qualified Text.PrettyPrint.ANSI.Leijen as P
12import qualified Elm.Package as Pkg
13import qualified Reporting.Error.Help as Help
17-- ERRORS
20data Error
21 = Application
22 | UnknownPackage Pkg.Name [Pkg.Name]
23 | UnknownVersion Pkg.Name Pkg.Version [Pkg.Version]
27-- TO DOC
30toReport :: Error -> Help.Report
31toReport err =
32 case err 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 [ P.indent 4 $ P.green $ "elm diff elm-lang/html 5.1.1 6.0.0"
38 ]
40 UnknownPackage pkg suggestions ->
41 Help.report "UNKNOWN PACKAGE" Nothing
42 ( "You are trying to diff against this package:"
43 )
44 [ P.indent 4 $ P.red $ P.text $ Pkg.toString pkg
45 , Help.stack $
46 case suggestions of
47 [] ->
48 [ "I cannot find that package though! Maybe there is a typo?"
49 ]
51 [suggestion] ->
52 [ "I cannot find that package though! Maybe you want this one instead?"
53 , P.indent 4 $ P.dullyellow $ P.text (Pkg.toString suggestion)
54 ]
56 _ ->
57 [ "I cannot find that package though! Maybe you want one of these instead?"
58 , P.indent 4 $ P.dullyellow $ P.vcat $ map (P.text . Pkg.toString) suggestions
59 ]
60 ]
62 UnknownVersion _pkg vsn realVersions ->
63 Help.docReport "UNKNOWN VERSION" Nothing
64 ( P.fillSep $
65 [ "Version", P.red (P.text (Pkg.versionToString vsn))
66 , "has", "never", "been", "published,", "so", "I"
67 , "cannot", "diff", "against", "it."
68 ]
69 )
70 [ "Here are all the versions that HAVE been published:"
71 , P.indent 4 $ P.dullyellow $ P.vcat $
72 let
73 sameMajor v1 v2 = Pkg._major v1 == Pkg._major v2
74 mkRow vsns = P.hsep $ map (P.text . Pkg.versionToString) vsns
75 in
76 map mkRow $ List.groupBy sameMajor (List.sort realVersions)
77 , "Want one of those instead?"
78 ]