diff options
author | Joey Hess <joeyh@joeyh.name> | 2015-07-13 10:44:51 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2015-07-13 10:44:51 -0400 |
commit | 3863b682b4a0fab70f1f03ac8e7957f17a3ee0b0 (patch) | |
tree | 65a7de0ee707c956ddf7ffe2c352865ab27e57fd /Command/Log.hs | |
parent | 533a5242b66831d56fb437fb356ef906b4b4fe0a (diff) |
converted Log
Diffstat (limited to 'Command/Log.hs')
-rw-r--r-- | Command/Log.hs | 65 |
1 files changed, 37 insertions, 28 deletions
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 |