on de2dbe0 help sign in
77 lines 2.3 kB history raw
1{-# LANGUAGE OverloadedStrings #-}
2module Reporting.Exit.Diff
3 ( Exit(..)
4 , toReport
5 )
6 where
8import qualified Data.List as List
9import qualified Text.PrettyPrint.ANSI.Leijen as P
11import qualified Elm.Package as Pkg
12import qualified Reporting.Exit.Help as Help
16-- EXITS
19data Exit
20 = Application
21 | UnknownPackage Pkg.Name [Pkg.Name]
22 | UnknownVersion Pkg.Name Pkg.Version [Pkg.Version]
26-- TO DOC
29toReport :: Exit -> Help.Report
30toReport exit =
31 case exit of
32 Application ->
33 Help.report "CANNOT DIFF APPLICATIONS" Nothing
34 "I cannot perform diffs on applications, only packages! If you are\
35 \ just curious to see a diff, try running this command:"
36 [ P.indent 4 $ P.green $ "elm diff elm-lang/html 5.1.1 6.0.0"
37 ]
39 UnknownPackage pkg suggestions ->
40 Help.report "UNKNOWN PACKAGE" Nothing
41 ( "You are trying to diff against this package:"
42 )
43 [ P.indent 4 $ P.red $ P.text $ Pkg.toString pkg
44 , Help.stack $
45 case suggestions of
46 [] ->
47 [ "I cannot find that package though! Maybe there is a typo?"
48 ]
50 [suggestion] ->
51 [ "I cannot find that package though! Maybe you want this one instead?"
52 , P.indent 4 $ P.dullyellow $ P.text (Pkg.toString suggestion)
53 ]
55 _ ->
56 [ "I cannot find that package though! Maybe you want one of these instead?"
57 , P.indent 4 $ P.dullyellow $ P.vcat $ map (P.text . Pkg.toString) suggestions
58 ]
59 ]
61 UnknownVersion _pkg vsn realVersions ->
62 Help.docReport "UNKNOWN VERSION" Nothing
63 ( P.fillSep $
64 [ "Version", P.red (P.text (Pkg.versionToString vsn))
65 , "has", "never", "been", "published,", "so", "I"
66 , "cannot", "diff", "against", "it."
67 ]
68 )
69 [ "Here are all the versions that HAVE been published:"
70 , P.indent 4 $ P.dullyellow $ P.vcat $
71 let
72 sameMajor v1 v2 = Pkg._major v1 == Pkg._major v2
73 mkRow vsns = P.hsep $ map (P.text . Pkg.versionToString) vsns
74 in
75 map mkRow $ List.groupBy sameMajor (List.sort realVersions)
76 , "Want one of those instead?"
77 ]