Skip to content

Commit

Permalink
implemented build-type option parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fabb committed Feb 15, 2019
1 parent b502767 commit f28dd91
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/CommandParsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,22 @@ platformsParser
filter (not . null) $ filter isLetter <$> wordsBy (not . isLetter) s
platformListOrError s = mapM platformOrError $ splitPlatforms s

buildTypeParser :: Opts.Parser BuildType
buildTypeParser = Opts.option
(eitherReader buildTypeOrError)
( Opts.value Carthage
<> Opts.metavar "TYPE"
<> Opts.long "build-type"
<> Opts.help "Build type of the project. One of Carthage or PodBuilder."
)
where
buildTypeOrError s = maybeToEither
( "Unrecognized build-type '"
++ s
++ "', expected 'Carthage' or 'PodBuilder'"
)
(readMaybe s)

udcPayloadParser :: Opts.Parser RomeUDCPayload
udcPayloadParser =
RomeUDCPayload
Expand All @@ -88,6 +104,7 @@ udcPayloadParser =
<*> skipLocalCacheParser
<*> noIgnoreParser
<*> noSkipCurrentParser
<*> buildTypeParser

uploadParser :: Opts.Parser RomeCommand
uploadParser = pure Upload <*> udcPayloadParser
Expand Down Expand Up @@ -133,6 +150,7 @@ listPayloadParser =
<*> printFormatParser
<*> noIgnoreParser
<*> noSkipCurrentParser
<*> buildTypeParser

listParser :: Opts.Parser RomeCommand
listParser = List <$> listPayloadParser
Expand Down
6 changes: 3 additions & 3 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ runUDCCommand command absoluteRomefilePath verbose romeVersion = do

case command of

Upload (RomeUDCPayload gitRepoNames platforms cachePrefixString skipLocalCache noIgnoreFlag noSkipCurrentFlag)
Upload (RomeUDCPayload gitRepoNames platforms cachePrefixString skipLocalCache noIgnoreFlag noSkipCurrentFlag buildType)
-> sayVersionWarning romeVersion verbose
*> performWithDefaultFlow
uploadArtifacts
Expand All @@ -138,7 +138,7 @@ runUDCCommand command absoluteRomefilePath verbose romeVersion = do
mlCacheDir
platforms

Download (RomeUDCPayload gitRepoNames platforms cachePrefixString skipLocalCache noIgnoreFlag noSkipCurrentFlag)
Download (RomeUDCPayload gitRepoNames platforms cachePrefixString skipLocalCache noIgnoreFlag noSkipCurrentFlag buildType)
-> sayVersionWarning romeVersion verbose
*> performWithDefaultFlow
downloadArtifacts
Expand All @@ -151,7 +151,7 @@ runUDCCommand command absoluteRomefilePath verbose romeVersion = do
mlCacheDir
platforms

List (RomeListPayload listMode platforms cachePrefixString printFormat noIgnoreFlag noSkipCurrentFlag)
List (RomeListPayload listMode platforms cachePrefixString printFormat noIgnoreFlag noSkipCurrentFlag buildType)
-> do

currentVersion <- deriveCurrentVersion
Expand Down
17 changes: 17 additions & 0 deletions src/Types/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ module Types.Commands where

import Data.Romefile
import Data.Carthage.TargetPlatform
import Text.Read
import qualified Text.Read.Lex as L
import Data.Char ( toLower )

data RomeCommand = Upload RomeUDCPayload
| Download RomeUDCPayload
Expand All @@ -18,6 +21,7 @@ data RomeUDCPayload = RomeUDCPayload { _payload :: [ProjectName]
, _skipLocalCacheFlag :: SkipLocalCacheFlag
, _noIgnoreFlag :: NoIgnoreFlag
, _noSkipCurrentFlag :: NoSkipCurrentFlag
, _buildType :: BuildType
}
deriving (Show, Eq)

Expand All @@ -39,12 +43,25 @@ newtype NoIgnoreFlag = NoIgnoreFlag { _noIgnore :: Bool }
newtype NoSkipCurrentFlag = NoSkipCurrentFlag { _noSkipCurrent :: Bool }
deriving (Show, Eq)

data BuildType = Carthage
| PodBuilder
deriving (Show, Eq)

instance Read BuildType where
readPrec = parens $ do
L.Ident s <- lexP
case map toLower s of
"carthage" -> return Carthage
"podbuilder" -> return PodBuilder
a -> error $ "Unrecognized BuildType '" ++ a ++ "'"

data RomeListPayload = RomeListPayload { _listMode :: ListMode
, _listPlatforms :: [TargetPlatform]
, _listCachePrefix :: String
, _listFormat :: PrintFormat
, _listNoIgnoreFlag :: NoIgnoreFlag
, _listNoSkipCurrentFlag :: NoSkipCurrentFlag
, _listBuildType :: BuildType
}
deriving (Show, Eq)

Expand Down

0 comments on commit f28dd91

Please sign in to comment.