1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 04:51:57 +03:00

Custom argument parsing for sha ranges and file paths

This commit is contained in:
Timothy Clem 2016-09-27 14:56:29 -07:00
parent 58d99a76c2
commit b8ad29fbca

View File

@ -1,25 +1,40 @@
module Arguments (Arguments(..), args) where
module Arguments (Arguments(..), ExtraArg(..), args, filePathsFromArgs, maybeShasFromArgs) where
import Data.Functor.Both
import qualified Prelude as P
import Data.Monoid
import Prelude
import qualified Renderer as R
data ExtraArg = ShaPair (Both (Maybe String)) | FileArg FilePath deriving (Show)
-- | The command line arguments to the application.
data Arguments = Arguments {
format :: R.Format,
maybeShas :: Both (Maybe P.String),
maybeTimeout :: Maybe Float,
output :: Maybe FilePath,
noIndex :: Bool,
filepaths :: [FilePath] }
deriving (Show)
data Arguments = Arguments
{ format :: R.Format
, maybeTimeout :: Maybe Float
, output :: Maybe FilePath
, noIndex :: Bool
, extraArgs :: [ExtraArg]
} deriving (Show)
args :: String -> String -> [String] -> R.Format -> Arguments
args sha1 sha2 filePaths format = Arguments { format = format
, maybeShas = Just <$> both sha1 sha2
, filepaths = filePaths
, maybeTimeout = Just 10.0
, output = Nothing
, noIndex = False
}
args sha1 sha2 filePaths format = Arguments
{ format = format
, maybeTimeout = Just 10.0
, output = Nothing
, noIndex = False
, extraArgs = [ShaPair (Just <$> both sha1 sha2)] <> (FileArg <$> filePaths)
}
filePathsFromArgs :: Arguments -> [FilePath]
filePathsFromArgs Arguments{..} = go extraArgs
where
go [] = []
go (FileArg x:xs) = x : go xs
go (_:xs) = go xs
maybeShasFromArgs :: Arguments -> Both (Maybe String)
maybeShasFromArgs Arguments{..} = go extraArgs
where
go [] = both Nothing Nothing
go (ShaPair x:_) = x
go (_:xs) = go xs