Types.hs 4.1 KB
Newer Older
1 2
{-# LANGUAGE DeriveGeneric #-}

3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
-----------------------------------------------------------------------------
-- |
-- Module      :  Distribution.Client.Init.Types
-- Copyright   :  (c) Brent Yorgey, Benedikt Huber 2009
-- License     :  BSD-like
--
-- Maintainer  :  cabal-devel@haskell.org
-- Stability   :  provisional
-- Portability :  portable
--
-- Some types used by the 'cabal init' command.
--
-----------------------------------------------------------------------------
module Distribution.Client.Init.Types where

Oleg Grenrus's avatar
Oleg Grenrus committed
18
import Distribution.Simple.Setup (Flag(..), toFlag )
19

20
import Distribution.Types.Dependency as P
21
import Distribution.Compat.Semigroup
22
import Distribution.Version
23
import Distribution.Verbosity
24
import qualified Distribution.Package as P
Oleg Grenrus's avatar
Oleg Grenrus committed
25
import Distribution.SPDX.License (License)
26
import Distribution.ModuleName
Oleg Grenrus's avatar
Oleg Grenrus committed
27
import Distribution.CabalSpecVersion
28
import Language.Haskell.Extension ( Language(..), Extension )
29 30

import qualified Text.PrettyPrint as Disp
31 32
import qualified Distribution.Deprecated.ReadP as Parse
import Distribution.Deprecated.Text
33

34
import GHC.Generics ( Generic )
35 36 37 38 39 40 41

-- | InitFlags is really just a simple type to represent certain
--   portions of a .cabal file.  Rather than have a flag for EVERY
--   possible field, we just have one for each field that the user is
--   likely to want and/or that we are likely to be able to
--   intelligently guess.
data InitFlags =
42
    InitFlags { interactive    :: Flag Bool
43 44 45 46
              , quiet          :: Flag Bool
              , packageDir     :: Flag FilePath
              , noComments     :: Flag Bool
              , minimal        :: Flag Bool
47
              , simpleProject  :: Flag Bool
48

Ian D. Bollinger's avatar
Ian D. Bollinger committed
49
              , packageName  :: Flag P.PackageName
50
              , version      :: Flag Version
Oleg Grenrus's avatar
Oleg Grenrus committed
51
              , cabalVersion :: Flag CabalSpecVersion
52 53 54 55 56 57 58
              , license      :: Flag License
              , author       :: Flag String
              , email        :: Flag String
              , homepage     :: Flag String

              , synopsis     :: Flag String
              , category     :: Flag (Either String Category)
59
              , extraSrc     :: Maybe [String]
60 61

              , packageType  :: Flag PackageType
Mikhail Glushenkov's avatar
Mikhail Glushenkov committed
62
              , mainIs       :: Flag FilePath
63
              , language     :: Flag Language
64 65 66

              , exposedModules :: Maybe [ModuleName]
              , otherModules   :: Maybe [ModuleName]
67
              , otherExts      :: Maybe [Extension]
68

69 70 71 72
              , dependencies    :: Maybe [P.Dependency]
              , applicationDirs :: Maybe [String]
              , sourceDirs      :: Maybe [String]
              , buildTools      :: Maybe [String]
73

74 75 76
              , initializeTestSuite :: Flag Bool
              , testDirs            :: Maybe [String]

77 78
              , initHcPath    :: Flag FilePath

79
              , initVerbosity :: Flag Verbosity
80
              , overwrite     :: Flag Bool
81
              }
82
  deriving (Show, Generic)
83

84 85 86 87
  -- the Monoid instance for Flag has later values override earlier
  -- ones, which is why we want Maybe [foo] for collecting foo values,
  -- not Flag [foo].

88
data BuildType = LibBuild | ExecBuild
89
  deriving Eq
90

91
-- The type of package to initialize.
92
data PackageType = Library | Executable | LibraryAndExecutable
93 94
  deriving (Show, Read, Eq)

95 96 97
displayPackageType :: PackageType -> String
displayPackageType LibraryAndExecutable = "Library and Executable"
displayPackageType pkgtype              = show pkgtype
98 99

instance Monoid InitFlags where
100
  mempty = gmempty
101 102 103
  mappend = (<>)

instance Semigroup InitFlags where
104
  (<>) = gmappend
105

Oleg Grenrus's avatar
Oleg Grenrus committed
106 107 108 109 110
defaultInitFlags :: InitFlags
defaultInitFlags  = mempty
    { initVerbosity = toFlag normal
    }

111
-- | Some common package categories (non-exhaustive list).
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
data Category
    = Codec
    | Concurrency
    | Control
    | Data
    | Database
    | Development
    | Distribution
    | Game
    | Graphics
    | Language
    | Math
    | Network
    | Sound
    | System
    | Testing
    | Text
    | Web
    deriving (Read, Show, Eq, Ord, Bounded, Enum)

instance Text Category where
  disp  = Disp.text . show
134
  parse = Parse.choice $ map (fmap read . Parse.string . show) [Codec .. ] -- TODO: eradicateNoParse