From 768996a0c92dae7d6df9f0e8dca7dccffa986488 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Sun, 1 Sep 2019 00:27:39 +0200 Subject: Keep the oldest days so that they can move to other groups --- README.md | 26 +++++++++++++++++--------- src/Main.hs | 8 +++++--- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index f33d831..4174d66 100644 --- a/README.md +++ b/README.md @@ -49,28 +49,36 @@ Different modes with the same days: ``` $ frotate --base 2 2019-08-31 2019-08-30 2019-08-29 2019-08-28 2019-08-27 2019-08-26 2019-08-25 2019-08-24 2019-08-31 -2019-08-30 2019-08-29 -2019-08-28 2019-08-27 2019-08-26 2019-08-25 +2019-08-29 2019-08-30 +2019-08-25 2019-08-26 2019-08-27 2019-08-28 2019-08-24 $ frotate --keep --base 2 2019-08-31 2019-08-30 2019-08-29 2019-08-28 2019-08-27 2019-08-26 2019-08-25 2019-08-24 -2019-08-31 2019-08-30 2019-08-28 2019-08-24 +2019-08-31 2019-08-29 2019-08-25 2019-08-24 $ frotate --delete --base 2 2019-08-31 2019-08-30 2019-08-29 2019-08-28 2019-08-27 2019-08-26 2019-08-25 2019-08-24 -2019-08-29 2019-08-27 2019-08-26 2019-08-25 +2019-08-30 2019-08-26 2019-08-27 2019-08-28 ``` More or less realistic example when we keep some backups and get new ones, but not every day: ``` $ frotate --keep --base 2 2019-09-01 2019-08-31 2019-08-30 2019-08-28 2019-08-24 -2019-09-01 2019-08-31 2019-08-28 2019-08-24 +2019-09-01 2019-08-30 2019-08-28 2019-08-24 -$ frotate --keep --base 2 2019-09-05 2019-09-01 2019-08-31 2019-08-28 2019-08-24 -2019-09-05 2019-09-01 2019-08-28 +$ frotate --keep --base 2 2019-09-05 2019-09-01 2019-08-30 2019-08-28 2019-08-24 +2019-09-05 2019-08-30 2019-08-24 -$ frotate --keep --base 2 2019-09-06 2019-09-05 2019-09-01 2019-08-28 -2019-09-06 2019-09-05 2019-09-01 2019-08-28 +$ frotate --keep --base 2 2019-09-06 2019-09-05 2019-08-30 2019-08-24 +2019-09-06 2019-09-05 2019-08-24 +$ frotate --keep --base 2 2019-09-07 2019-09-06 2019-09-05 2019-08-24 +2019-09-07 2019-09-05 2019-08-24 + +$ frotate --keep --base 2 2019-09-08 2019-09-07 2019-09-06 2019-08-24 +2019-09-08 2019-09-06 2019-08-24 + +$ frotate --keep --base 2 2019-09-09 2019-09-08 2019-09-06 2019-08-24 +2019-09-09 2019-09-08 2019-09-06 2019-08-24 ``` diff --git a/src/Main.hs b/src/Main.hs index 0ab3259..0f66daa 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -60,6 +60,8 @@ main = do opts <- execParser $ info (parseOptions <**> helper) fullDesc let groups = partitionDays (\n -> floor (base opts ^ (n - 1))) (days opts) case mode opts of - Just Keep -> putStrLn $ unwords . map show . concatMap (take 1) $ groups - Just Delete -> putStrLn $ unwords . map show . concatMap (drop 1) $ groups - Nothing -> mapM_ (hPutStrLn stderr . unwords . map show) groups + Just Keep -> + putStrLn $ unwords . map show . concatMap (take 1 . reverse) $ groups + Just Delete -> + putStrLn $ unwords . map show . concatMap (drop 1 . reverse) $ groups + Nothing -> mapM_ (hPutStrLn stderr . unwords . map show . reverse) groups -- cgit v1.2.3