module HMGit.Commands.Plumbing.CatFile.Cmd ( catFileCmd ) where import HMGit.Commands (Cmd (..)) import HMGit.Commands.Plumbing.CatFile.Core (CatFile, catOptObjectPP, catOptObjectSize, catOptObjectType) import Control.Exception.Safe (MonadThrow) import Control.Monad.IO.Class (MonadIO) import Data.Foldable (asum) import qualified Options.Applicative as OA catFileMode :: (MonadThrow m, MonadIO m) => OA.Parser (CatFile m) catFileMode :: Parser (CatFile m) catFileMode = [Parser (CatFile m)] -> Parser (CatFile m) forall (t :: * -> *) (f :: * -> *) a. (Foldable t, Alternative f) => t (f a) -> f a asum [ CatFile m -> Mod FlagFields (CatFile m) -> Parser (CatFile m) forall a. a -> Mod FlagFields a -> Parser a OA.flag' CatFile m forall (m :: * -> *). MonadIO m => CatFile m catOptObjectType (Mod FlagFields (CatFile m) -> Parser (CatFile m)) -> Mod FlagFields (CatFile m) -> Parser (CatFile m) forall a b. (a -> b) -> a -> b $ [Mod FlagFields (CatFile m)] -> Mod FlagFields (CatFile m) forall a. Monoid a => [a] -> a mconcat [ Char -> Mod FlagFields (CatFile m) forall (f :: * -> *) a. HasName f => Char -> Mod f a OA.short Char 't' , String -> Mod FlagFields (CatFile m) forall (f :: * -> *) a. String -> Mod f a OA.help String "Instead of content, show the object type identified by <object>." ] , CatFile m -> Mod FlagFields (CatFile m) -> Parser (CatFile m) forall a. a -> Mod FlagFields a -> Parser a OA.flag' CatFile m forall (m :: * -> *). MonadIO m => CatFile m catOptObjectSize (Mod FlagFields (CatFile m) -> Parser (CatFile m)) -> Mod FlagFields (CatFile m) -> Parser (CatFile m) forall a b. (a -> b) -> a -> b $ [Mod FlagFields (CatFile m)] -> Mod FlagFields (CatFile m) forall a. Monoid a => [a] -> a mconcat [ Char -> Mod FlagFields (CatFile m) forall (f :: * -> *) a. HasName f => Char -> Mod f a OA.short Char 's' , String -> Mod FlagFields (CatFile m) forall (f :: * -> *) a. String -> Mod f a OA.help String "Instead of the content, show the object size identified by <object>." ] , CatFile m -> Mod FlagFields (CatFile m) -> Parser (CatFile m) forall a. a -> Mod FlagFields a -> Parser a OA.flag' CatFile m forall (m :: * -> *). (MonadIO m, MonadThrow m) => CatFile m catOptObjectPP (Mod FlagFields (CatFile m) -> Parser (CatFile m)) -> Mod FlagFields (CatFile m) -> Parser (CatFile m) forall a b. (a -> b) -> a -> b $ [Mod FlagFields (CatFile m)] -> Mod FlagFields (CatFile m) forall a. Monoid a => [a] -> a mconcat [ Char -> Mod FlagFields (CatFile m) forall (f :: * -> *) a. HasName f => Char -> Mod f a OA.short Char 'p' , String -> Mod FlagFields (CatFile m) forall (f :: * -> *) a. String -> Mod f a OA.help String "Pretty-print the contents of <object> based on its type." ] , Mod ArgumentFields (CatFile m) -> Parser (CatFile m) forall s. IsString s => Mod ArgumentFields s -> Parser s OA.strArgument (Mod ArgumentFields (CatFile m) -> Parser (CatFile m)) -> Mod ArgumentFields (CatFile m) -> Parser (CatFile m) forall a b. (a -> b) -> a -> b $ [Mod ArgumentFields (CatFile m)] -> Mod ArgumentFields (CatFile m) forall a. Monoid a => [a] -> a mconcat [ String -> Mod ArgumentFields (CatFile m) forall (f :: * -> *) a. HasMetavar f => String -> Mod f a OA.metavar String "<type>" , String -> Mod ArgumentFields (CatFile m) forall (f :: * -> *) a. String -> Mod f a OA.help (String -> Mod ArgumentFields (CatFile m)) -> String -> Mod ArgumentFields (CatFile m) forall a b. (a -> b) -> a -> b $ [String] -> String unwords [ String "Typically this matches the real of <object> but asking for a" , String "type that can trivially be dereferenced from the given <object>" , String "is also permitted. An example is to ask for a \"tree\" with" , String "<object> being a commit object that contains it, or to ask for" , String "a \"blob\" with <object> being a tag object that points at it." ] ] ] objectName :: OA.Parser String objectName :: Parser String objectName = Mod ArgumentFields String -> Parser String forall s. IsString s => Mod ArgumentFields s -> Parser s OA.strArgument (Mod ArgumentFields String -> Parser String) -> Mod ArgumentFields String -> Parser String forall a b. (a -> b) -> a -> b $ [Mod ArgumentFields String] -> Mod ArgumentFields String forall a. Monoid a => [a] -> a mconcat [ String -> Mod ArgumentFields String forall (f :: * -> *) a. HasMetavar f => String -> Mod f a OA.metavar String "<object>" , String -> Mod ArgumentFields String forall (f :: * -> *) a. String -> Mod f a OA.help String "Set as an option dedicated to cat-file" ] catFileCmd :: (MonadThrow m, MonadIO m) => OA.Mod OA.CommandFields (Cmd m) catFileCmd :: Mod CommandFields (Cmd m) catFileCmd = String -> ParserInfo (Cmd m) -> Mod CommandFields (Cmd m) forall a. String -> ParserInfo a -> Mod CommandFields a OA.command String "cat-file" (ParserInfo (Cmd m) -> Mod CommandFields (Cmd m)) -> ParserInfo (Cmd m) -> Mod CommandFields (Cmd m) forall a b. (a -> b) -> a -> b $ Parser (Cmd m) -> InfoMod (Cmd m) -> ParserInfo (Cmd m) forall a. Parser a -> InfoMod a -> ParserInfo a OA.info (CatFile m -> String -> Cmd m forall (m :: * -> *). CatFile m -> String -> Cmd m CmdCatFile (CatFile m -> String -> Cmd m) -> Parser (CatFile m) -> Parser (String -> Cmd m) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b <$> (Parser (CatFile m -> CatFile m) forall a. Parser (a -> a) OA.helper Parser (CatFile m -> CatFile m) -> Parser (CatFile m) -> Parser (CatFile m) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Parser (CatFile m) forall (m :: * -> *). (MonadThrow m, MonadIO m) => Parser (CatFile m) catFileMode) Parser (String -> Cmd m) -> Parser String -> Parser (Cmd m) forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b <*> Parser String objectName) (InfoMod (Cmd m) -> ParserInfo (Cmd m)) -> InfoMod (Cmd m) -> ParserInfo (Cmd m) forall a b. (a -> b) -> a -> b $ String -> InfoMod (Cmd m) forall a. String -> InfoMod a OA.progDesc String "Provide content or type and size information for repository objects"