Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 90 lines (73 sloc) 2.702 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
c650e34 @ttuegel D.Compat.Binary: backport binary generics to binary-0.5
ttuegel authored
27 import Distribution.Compat.Binary (Binary)
b4c82ce @pepeiborra custom show'ers for Verbosity
pepeiborra authored
28 import Data.List (elemIndex)
7bbbe59 @pepeiborra #223 part 1: Extend Distribution.Command.Simple.Option
pepeiborra authored
29 import Distribution.ReadE
7e75975 @ttuegel Add instance Binary LocalBuildInfo
ttuegel authored
30 import GHC.Generics
b4c82ce @pepeiborra custom show'ers for Verbosity
pepeiborra authored
31
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
32 data Verbosity = Silent | Normal | Verbose | Deafening
7e75975 @ttuegel Add instance Binary LocalBuildInfo
ttuegel authored
33 deriving (Generic, Show, Read, Eq, Ord, Enum, Bounded)
34
35 instance Binary Verbosity
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
36
386acb1 @igfoo Put some comments in about what the verbosity stuff means
igfoo authored
37 -- 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
38 silent :: Verbosity
39 silent = Silent
40
386acb1 @igfoo Put some comments in about what the verbosity stuff means
igfoo authored
41 -- Print stuff we want to see by default
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
42 normal :: Verbosity
43 normal = Normal
44
386acb1 @igfoo Put some comments in about what the verbosity stuff means
igfoo authored
45 -- Be more verbose about what's going on
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
46 verbose :: Verbosity
47 verbose = Verbose
48
386acb1 @igfoo Put some comments in about what the verbosity stuff means
igfoo authored
49 -- Not only are we verbose ourselves (perhaps even noisier than when
50 -- 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
51 deafening :: Verbosity
73ca74a fix cut&pasto
Simon Marlow authored
52 deafening = Deafening
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
53
da01c73 @dcoutts Make configure much less verbose by default and give useful output wi…
dcoutts authored
54 moreVerbose :: Verbosity -> Verbosity
55 moreVerbose Silent = Silent --silent should stay silent
56 moreVerbose Normal = Verbose
57 moreVerbose Verbose = Deafening
58 moreVerbose Deafening = Deafening
59
60 lessVerbose :: Verbosity -> Verbosity
6696ad5 @dcoutts Print exit code and stderr for failing progs at debug level verbosity
dcoutts authored
61 lessVerbose Deafening = Deafening
da01c73 @dcoutts Make configure much less verbose by default and give useful output wi…
dcoutts authored
62 lessVerbose Verbose = Normal
63 lessVerbose Normal = Silent
64 lessVerbose Silent = Silent
65
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
66 intToVerbosity :: Int -> Maybe Verbosity
67 intToVerbosity 0 = Just Silent
68 intToVerbosity 1 = Just Normal
69 intToVerbosity 2 = Just Verbose
70 intToVerbosity 3 = Just Deafening
71 intToVerbosity _ = Nothing
72
7bbbe59 @pepeiborra #223 part 1: Extend Distribution.Command.Simple.Option
pepeiborra authored
73 flagToVerbosity :: ReadE Verbosity
74 flagToVerbosity = ReadE $ \s ->
75 case reads s of
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
76 [(i, "")] ->
77 case intToVerbosity i of
7bbbe59 @pepeiborra #223 part 1: Extend Distribution.Command.Simple.Option
pepeiborra authored
78 Just v -> Right v
79 Nothing -> Left ("Bad verbosity: " ++ show i ++
80 ". Valid values are 0..3")
81 _ -> Left ("Can't parse verbosity " ++ s)
2884743 @igfoo Make a proper verbosity type, rather than using Int values
igfoo authored
82
b4c82ce @pepeiborra custom show'ers for Verbosity
pepeiborra authored
83 showForCabal, showForGHC :: Verbosity -> String
91d44fc @pepeiborra Get right the verbosity correspondence for GHC
pepeiborra authored
84
ea60654 @RossPaterson portability fix
RossPaterson authored
85 showForCabal v = maybe (error "unknown verbosity") show $
86 elemIndex v [silent,normal,verbose,deafening]
87 showForGHC v = maybe (error "unknown verbosity") show $
91d44fc @pepeiborra Get right the verbosity correspondence for GHC
pepeiborra authored
88 elemIndex v [silent,normal,__,verbose,deafening]
89 where __ = silent -- this will be always ignored by elemIndex
Something went wrong with that request. Please try again.