1
1
mirror of https://github.com/github/semantic.git synced 2025-01-08 08:30:27 +03:00

Merge branch 'diff-with-no-index-args-parse' into diff-with-no-index

This commit is contained in:
Timothy Clem 2016-09-29 14:12:13 -07:00
commit a269e6c28a

View File

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