Skip to content

Commit

Permalink
Add --romefile CLI option to all commands
Browse files Browse the repository at this point in the history
  • Loading branch information
tmspzz committed Aug 24, 2018
1 parent 0591429 commit 4ae626b
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Rome.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Rome
version: 0.17.0.48
version: 0.17.1.49
synopsis: A cache for Carthage
description: Please see README.md
homepage: https://github.com/blender/Rome
Expand Down
2 changes: 1 addition & 1 deletion Rome.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'Rome'
s.version = '0.17.0.48'
s.version = '0.17.1.49'
s.summary = 'A cache tool for Carthage'
s.homepage = 'https://github.com/blender/Rome'
s.source = { :http => "#{s.homepage}/releases/download/v#{s.version}/rome.zip" }
Expand Down
2 changes: 1 addition & 1 deletion app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import System.Exit


romeVersion :: RomeVersion
romeVersion = (0, 17, 0, 48)
romeVersion = (0, 17, 1, 49)



Expand Down
18 changes: 13 additions & 5 deletions src/CommandParsers.hs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import Types.Commands
-- verifyParser :: Parser VerifyFlag
-- verifyParser = VerifyFlag <$> Opts.switch ( Opts.long "verify" <> Opts.help "Verify that the framework has the same hash as specified in the Cartfile.resolved.")

cachePrefixParser :: Parser String
cachePrefixParser :: Opts.Parser String
cachePrefixParser = Opts.strOption
( Opts.value ""
<> Opts.metavar "PREFIX"
Expand All @@ -29,13 +29,13 @@ cachePrefixParser = Opts.strOption
"A prefix appended to the top level directories inside the caches. Usefull to separate artifacts between Swift versions."
)

skipLocalCacheParser :: Parser SkipLocalCacheFlag
skipLocalCacheParser :: Opts.Parser SkipLocalCacheFlag
skipLocalCacheParser = SkipLocalCacheFlag <$> Opts.switch
( Opts.long "skip-local-cache"
<> Opts.help "Ignore the local cache when performing the operation."
)

noIgnoreParser :: Parser NoIgnoreFlag
noIgnoreParser :: Opts.Parser NoIgnoreFlag
noIgnoreParser = NoIgnoreFlag <$> Opts.switch
( Opts.long "no-ignore"
<> Opts.help
Expand Down Expand Up @@ -139,10 +139,18 @@ romeUtilsSubcommandParser = Opts.subparser
`withInfo` "Migrates a Romefile from INI to YAML."
)


utilsParser :: Opts.Parser RomeCommand
utilsParser = Utils <$> utilsPayloadParser

parseRomefilePath :: Opts.Parser String
parseRomefilePath = Opts.strOption
( Opts.value canonicalRomefileName
<> Opts.metavar "PATH"
<> Opts.long "romefile"
<> Opts.help
"The path to the Romemefile to use. Defaults the Romefile in then current directory."
)

parseRomeCommand :: Opts.Parser RomeCommand
parseRomeCommand =
Opts.subparser
Expand All @@ -168,7 +176,7 @@ parseRomeCommand =
)

parseRomeOptions :: Opts.Parser RomeOptions
parseRomeOptions = RomeOptions <$> parseRomeCommand <*> Opts.switch
parseRomeOptions = RomeOptions <$> parseRomeCommand <*> parseRomefilePath <*> Opts.switch
(Opts.short 'v' <> help "Show verbose output")

withInfo :: Opts.Parser a -> String -> Opts.ParserInfo a
Expand Down
10 changes: 5 additions & 5 deletions src/Configuration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ getCartfileEntires = do
Left e -> throwError $ "Carfile.resolved parse error: " ++ show e
Right cartfileEntries -> return cartfileEntries

getRomefileEntries :: RomeMonad Romefile
getRomefileEntries =
let fromYaml = ExceptT $ left prettyPrintParseException <$> decodeFileEither romefileName
fromIni = ExceptT $ parseRomefile <$> T.readFile romefileName
getRomefileEntries :: FilePath -> RomeMonad Romefile
getRomefileEntries absoluteRomefilePath =
let fromYaml = ExceptT $ left prettyPrintParseException <$> decodeFileEither absoluteRomefilePath
fromIni = ExceptT $ parseRomefile <$> T.readFile absoluteRomefilePath
in
withExceptT toErr $ fromYaml <|> fromIni
where toErr e = "Error while parsing " <> romefileName <> ": " <> e
where toErr e = "Error while parsing " <> absoluteRomefilePath <> ": " <> e

getS3ConfigFile :: MonadIO m => m FilePath
getS3ConfigFile = (</> awsConfigFilePath) `liftM` liftIO getHomeDirectory
Expand Down
8 changes: 4 additions & 4 deletions src/Data/Romefile.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

module Data.Romefile
( parseRomefile
, romefileName
, canonicalRomefileName
, RomefileEntry (..)
, Framework (..)
, ProjectName (..)
Expand Down Expand Up @@ -188,9 +188,9 @@ bucket = lens _bucket (\cInfo n -> cInfo { _bucket = n })
localCacheDir :: Lens' RomeCacheInfo (Maybe FilePath)
localCacheDir = lens _localCacheDir (\cInfo n -> cInfo { _localCacheDir = n })

-- |The name of the Romefile
romefileName :: String
romefileName = "Romefile"
-- |The canonical name of the Romefile
canonicalRomefileName :: String
canonicalRomefileName = "Romefile"

-- |The delimiter of the CACHE section a Romefile
cacheSectionDelimiter :: T.Text
Expand Down
24 changes: 13 additions & 11 deletions src/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -96,22 +96,24 @@ runRomeWithOptions
:: RomeOptions -- ^ The `RomeOptions` to run Rome with.
-> RomeVersion
-> RomeMonad ()
runRomeWithOptions (RomeOptions options verbose) romeVersion = case options of
Utils utilsPayload -> runUtilsCommand options verbose romeVersion
otherCommad -> runUDCCommand options verbose romeVersion

runUtilsCommand :: RomeCommand -> Bool -> RomeVersion -> RomeMonad ()
runUtilsCommand command verbose romeVersion = do
runRomeWithOptions (RomeOptions options romefilePath verbose) romeVersion = do
absoluteRomefilePath <- liftIO $ absolutizePath romefilePath
case options of
Utils utilsPayload -> runUtilsCommand options absoluteRomefilePath verbose romeVersion
otherCommad -> runUDCCommand options absoluteRomefilePath verbose romeVersion

runUtilsCommand :: RomeCommand -> FilePath -> Bool -> RomeVersion -> RomeMonad ()
runUtilsCommand command absoluteRomefilePath verbose romeVersion =
case command of
Utils _ -> do
romeFileEntries <- getRomefileEntries
lift $ encodeFile romefileName romeFileEntries
romeFileEntries <- getRomefileEntries absoluteRomefilePath
lift $ encodeFile absoluteRomefilePath romeFileEntries
_ -> throwError "Error: Programming Error. Only Utils command supported."

runUDCCommand :: RomeCommand -> Bool -> RomeVersion -> RomeMonad ()
runUDCCommand command verbose romeVersion = do
runUDCCommand :: RomeCommand -> FilePath -> Bool -> RomeVersion -> RomeMonad ()
runUDCCommand command absoluteRomefilePath verbose romeVersion = do
cartfileEntries <- getCartfileEntires
romeFile <- getRomefileEntries
romeFile <- getRomefileEntries absoluteRomefilePath

let ignoreMapEntries = _ignoreMapEntries romeFile
let repositoryMapEntries = _repositoryMapEntries romeFile
Expand Down
1 change: 1 addition & 0 deletions src/Types/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ data ListMode = All
deriving (Show, Eq)

data RomeOptions = RomeOptions { romeCommand :: RomeCommand
, romefilePath :: FilePath
, verbose :: Bool
}
deriving (Show, Eq)

0 comments on commit 4ae626b

Please sign in to comment.