diff options
author | Joey Hess <joey@kitenet.net> | 2013-10-07 17:11:13 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-10-07 17:11:13 -0400 |
commit | 864ac0a7c16f227f1f1f3e5c30ea7f544e04f451 (patch) | |
tree | 4209bbe03d6e454eab1324d858e5db3781f57283 /Types/ScheduledActivity.hs | |
parent | ab18b011b18da821441be71ffafc47a627c1f4b8 (diff) |
add schedule to vicfg
Diffstat (limited to 'Types/ScheduledActivity.hs')
-rw-r--r-- | Types/ScheduledActivity.hs | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/Types/ScheduledActivity.hs b/Types/ScheduledActivity.hs index e2b8d088a..7e76cadfe 100644 --- a/Types/ScheduledActivity.hs +++ b/Types/ScheduledActivity.hs @@ -14,18 +14,25 @@ import Types.UUID data ScheduledActivity = ScheduledSelfFsck Schedule | ScheduledRemoteFsck UUID Schedule + deriving (Eq, Show, Ord) fromScheduledActivity :: ScheduledActivity -> String fromScheduledActivity (ScheduledSelfFsck s) = - "fsck self at " ++ fromSchedule s + "fsck self " ++ fromSchedule s fromScheduledActivity (ScheduledRemoteFsck u s) = - "fsck " ++ fromUUID u ++ " at " ++ fromSchedule s + "fsck " ++ fromUUID u ++ fromSchedule s toScheduledActivity :: String -> Maybe ScheduledActivity -toScheduledActivity s = case words s of - ("fsck":"self":rest) -> ScheduledSelfFsck - <$> toSchedule (unwords rest) - ("fsck":u:rest) -> ScheduledRemoteFsck +toScheduledActivity = eitherToMaybe . parseScheduledActivity + +parseScheduledActivity :: String -> Either String ScheduledActivity +parseScheduledActivity s = case words s of + ("fsck":"self":rest) -> qualified $ ScheduledSelfFsck + <$> parseSchedule (unwords rest) + ("fsck":u:rest) -> qualified $ ScheduledRemoteFsck <$> pure (toUUID u) - <*> toSchedule (unwords rest) - _ -> Nothing + <*> parseSchedule (unwords rest) + _ -> qualified $ Left "unknown activity" + where + qualified (Left e) = Left $ e ++ " in \"" ++ s ++ "\"" + qualified v = v |