Skip to content
Newer
Older
100644 91 lines (73 sloc) 2.63 KB
7e75975 @ttuegel Add instance Binary LocalBuildInfo
ttuegel authored
1 {-# LANGUAGE DeriveGeneric #-}
2
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
3 -----------------------------------------------------------------------------
4 -- |
5 -- Module : Distribution.Verbosity
6 -- Copyright : Ian Lynagh 2007
750ba1c @23Skidoo Remove the BSD3 text from file headers.
23Skidoo authored
7 -- License : BSD3
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
8 --
0c993c8 @dcoutts Update module headers
dcoutts authored
9 -- Maintainer : cabal-devel@haskell.org
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
10 -- Portability : portable
11 --
0c993c8 @dcoutts Update module headers
dcoutts authored
12 -- A simple 'Verbosity' type with associated utilities. There are 4 standard
13 -- verbosity levels from 'silent', 'normal', 'verbose' up to 'deafening'. This
14 -- is used for deciding what logging messages to print.
15
750ba1c @23Skidoo Remove the BSD3 text from file headers.
23Skidoo authored
16 -- Verbosity for Cabal functions.
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
17
18 module Distribution.Verbosity (
19 -- * Verbosity
20 Verbosity,
21 silent, normal, verbose, deafening,
da01c73 @dcoutts Make configure much less verbose by default and give useful output wi…
dcoutts authored
22 moreVerbose, lessVerbose,
b4c82ce @pepeiborra custom show'ers for Verbosity
pepeiborra authored
23 intToVerbosity, flagToVerbosity,
24 showForCabal, showForGHC
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
25 ) where
26
639cd00 @ezyang Remove same-package import lists, fixes #2835.
ezyang authored
27 import Distribution.Compat.Binary
7bbbe59 @pepeiborra #223 part 1: Extend Distribution.Command.Simple.Option
pepeiborra authored
28 import Distribution.ReadE
639cd00 @ezyang Remove same-package import lists, fixes #2835.
ezyang authored
29
30 import Data.List (elemIndex)
7e75975 @ttuegel Add instance Binary LocalBuildInfo
ttuegel authored
31 import GHC.Generics
b4c82ce @pepeiborra custom show'ers for Verbosity
pepeiborra authored
32
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
33 data Verbosity = Silent | Normal | Verbose | Deafening
7e75975 @ttuegel Add instance Binary LocalBuildInfo
ttuegel authored
34 deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded)
35
36 instance Binary Verbosity
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
37
386acb1 @igfoo Put some comments in about what the verbosity stuff means
igfoo authored
38 -- We shouldn't print /anything/ unless an error occurs in silent mode
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
39 silent :: Verbosity
40 silent = Silent
41
386acb1 @igfoo Put some comments in about what the verbosity stuff means
igfoo authored
42 -- Print stuff we want to see by default
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
43 normal :: Verbosity
44 normal = Normal
45
386acb1 @igfoo Put some comments in about what the verbosity stuff means
igfoo authored
46 -- Be more verbose about what's going on
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
47 verbose :: Verbosity
48 verbose = Verbose
49
386acb1 @igfoo Put some comments in about what the verbosity stuff means
igfoo authored
50 -- Not only are we verbose ourselves (perhaps even noisier than when
51 -- being "verbose"), but we tell everything we run to be verbose too
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
52 deafening :: Verbosity
73ca74a fix cut&pasto
Simon Marlow authored
53 deafening = Deafening
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
54
da01c73 @dcoutts Make configure much less verbose by default and give useful output wi…
dcoutts authored
55 moreVerbose :: Verbosity -> Verbosity
56 moreVerbose Silent = Silent --silent should stay silent
57 moreVerbose Normal = Verbose
58 moreVerbose Verbose = Deafening
59 moreVerbose Deafening = Deafening
60
61 lessVerbose :: Verbosity -> Verbosity
6696ad5 @dcoutts Print exit code and stderr for failing progs at debug level verbosity
dcoutts authored
62 lessVerbose Deafening = Deafening
da01c73 @dcoutts Make configure much less verbose by default and give useful output wi…
dcoutts authored
63 lessVerbose Verbose = Normal
64 lessVerbose Normal = Silent
65 lessVerbose Silent = Silent
66
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
67 intToVerbosity :: Int -> Maybe Verbosity
68 intToVerbosity 0 = Just Silent
69 intToVerbosity 1 = Just Normal
70 intToVerbosity 2 = Just Verbose
71 intToVerbosity 3 = Just Deafening
72 intToVerbosity _ = Nothing
73
7bbbe59 @pepeiborra #223 part 1: Extend Distribution.Command.Simple.Option
pepeiborra authored
74 flagToVerbosity :: ReadE Verbosity
75 flagToVerbosity = ReadE $ \s ->
76 case reads s of
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
77 [(i, "")] ->
78 case intToVerbosity i of
7bbbe59 @pepeiborra #223 part 1: Extend Distribution.Command.Simple.Option
pepeiborra authored
79 Just v -> Right v
80 Nothing -> Left ("Bad verbosity: " ++ show i ++
81 ". Valid values are 0..3")
82 _ -> Left ("Can't parse verbosity " ++ s)
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
83
b4c82ce @pepeiborra custom show'ers for Verbosity
pepeiborra authored
84 showForCabal, showForGHC :: Verbosity -> String
91d44fc @pepeiborra Get right the verbosity correspondence for GHC
pepeiborra authored
85
ea60654 @RossPaterson portability fix
RossPaterson authored
86 showForCabal v = maybe (error "unknown verbosity") show $
87 elemIndex v [silent,normal,verbose,deafening]
88 showForGHC v = maybe (error "unknown verbosity") show $
91d44fc @pepeiborra Get right the verbosity correspondence for GHC
pepeiborra authored
89 elemIndex v [silent,normal,__,verbose,deafening]
90 where __ = silent -- this will be always ignored by elemIndex
Something went wrong with that request. Please try again.