From 3863b682b4a0fab70f1f03ac8e7957f17a3ee0b0 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 13 Jul 2015 10:44:51 -0400 Subject: converted Log --- Command/Log.hs | 65 +++++++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 28 deletions(-) (limited to 'Command/Log.hs') diff --git a/Command/Log.hs b/Command/Log.hs index eb740b249..86b32b937 100644 --- a/Command/Log.hs +++ b/Command/Log.hs @@ -39,52 +39,61 @@ data RefChange = RefChange type Outputter = Bool -> POSIXTime -> [UUID] -> Annex () cmd :: Command -cmd = withGlobalOptions options $ +cmd = withGlobalOptions annexedMatchingOptions $ command "log" SectionQuery "shows location log" - paramPaths (withParams seek) + paramPaths (seek <$$> optParser) -options :: [GlobalOption] -options = passthruOptions ++ [gourceOption] ++ annexedMatchingOptions +data LogOptions = LogOptions + { logFiles :: CmdParams + , gourceOption :: Bool + , passthruOptions :: [CommandParam] + } -passthruOptions :: [Option] -passthruOptions = map odate ["since", "after", "until", "before"] ++ - [ fieldOption ['n'] "max-count" paramNumber - "limit number of logs displayed" - ] +optParser :: CmdParamsDesc -> Parser LogOptions +optParser desc = LogOptions + <$> cmdParams desc + <*> switch + ( long "gource" + <> help "format output for gource" + ) + <*> (concat <$> many passthru) where - odate n = fieldOption [] n paramDate $ "show log " ++ n ++ " date" - -gourceOption :: Option -gourceOption = flagOption [] "gource" "format output for gource" - -seek :: CmdParams -> CommandSeek -seek ps = do + passthru :: Parser [CommandParam] + passthru = datepassthru "since" + <|> datepassthru "after" + <|> datepassthru "until" + <|> datepassthru "before" + <|> (mkpassthru "max-count" <$> strOption + ( long "max-count" <> metavar paramNumber + <> help "limit number of logs displayed" + )) + datepassthru n = mkpassthru n <$> strOption + ( long n <> metavar paramDate + <> help ("show log " ++ n ++ " date") + ) + mkpassthru n v = [Param ("--" ++ n), Param v] + +seek :: LogOptions -> CommandSeek +seek o = do m <- Remote.uuidDescriptions zone <- liftIO getCurrentTimeZone - os <- concat <$> mapM getoption passthruOptions - gource <- getOptionFlag gourceOption - withFilesInGit (whenAnnexed $ start m zone os gource) ps - where - getoption o = maybe [] (use o) <$> - Annex.getField (optionName o) - use o v = [Param ("--" ++ optionName o), Param v] + withFilesInGit (whenAnnexed $ start m zone o) (logFiles o) start :: M.Map UUID String -> TimeZone - -> [CommandParam] - -> Bool + -> LogOptions -> FilePath -> Key -> CommandStart -start m zone os gource file key = do - showLog output =<< readLog <$> getLog key os +start m zone o file key = do + showLog output =<< readLog <$> getLog key (passthruOptions o) -- getLog produces a zombie; reap it liftIO reapZombies stop where output - | gource = gourceOutput lookupdescription file + | (gourceOption o) = gourceOutput lookupdescription file | otherwise = normalOutput lookupdescription file zone lookupdescription u = fromMaybe (fromUUID u) $ M.lookup u m -- cgit v1.2.3