2018-03-31 06:07:46 +03:00
|
|
|
{-# LANGUAGE ExtendedDefaultRules #-}
|
2018-04-04 12:24:55 +03:00
|
|
|
{-# LANGUAGE OverloadedStrings #-}
|
2018-03-31 06:07:46 +03:00
|
|
|
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
|
2018-04-04 12:24:55 +03:00
|
|
|
|
|
|
|
import Control.Applicative ((<**>), (<|>))
|
2018-04-03 07:56:00 +03:00
|
|
|
import Control.Exception
|
2018-04-04 12:24:55 +03:00
|
|
|
import Data.Maybe (isJust)
|
|
|
|
import Data.Semigroup ((<>))
|
2018-03-31 06:07:46 +03:00
|
|
|
import qualified Data.Text as T
|
|
|
|
import Data.Text (Text)
|
2018-07-11 05:30:34 +03:00
|
|
|
import qualified Data.Text.IO as T
|
2018-09-06 16:47:09 +03:00
|
|
|
import DeleteMerged (deleteDone)
|
2018-04-04 02:03:46 +03:00
|
|
|
import qualified Options.Applicative as Opt
|
2018-09-06 16:47:09 +03:00
|
|
|
import System.Directory (getHomeDirectory)
|
2018-07-11 05:30:34 +03:00
|
|
|
import System.Posix.Env (getEnv)
|
2018-04-04 12:24:55 +03:00
|
|
|
import Update (updateAll)
|
2018-12-02 06:59:55 +03:00
|
|
|
import Utils (Options(..), setupNixpkgs)
|
2018-04-04 02:03:46 +03:00
|
|
|
|
2018-03-31 06:07:46 +03:00
|
|
|
default (T.Text)
|
|
|
|
|
2018-04-04 12:24:55 +03:00
|
|
|
data Mode
|
2018-04-06 18:17:22 +03:00
|
|
|
= Update
|
2018-09-06 16:47:09 +03:00
|
|
|
| DeleteDone
|
2018-04-04 02:03:46 +03:00
|
|
|
|
|
|
|
modeParser :: Opt.Parser Mode
|
|
|
|
modeParser =
|
2018-04-06 18:17:22 +03:00
|
|
|
Opt.flag'
|
|
|
|
Update
|
|
|
|
(Opt.long "update" <> Opt.help "Update packages (default mode)") <|>
|
|
|
|
Opt.flag'
|
2018-09-06 16:47:09 +03:00
|
|
|
DeleteDone
|
|
|
|
(Opt.long "delete-done" <>
|
|
|
|
Opt.help "Delete branches from PRs that were merged or closed")
|
2018-04-04 02:03:46 +03:00
|
|
|
|
|
|
|
programInfo :: Opt.ParserInfo Mode
|
2018-04-06 18:17:22 +03:00
|
|
|
programInfo =
|
|
|
|
Opt.info
|
|
|
|
(modeParser <**> Opt.helper)
|
|
|
|
(Opt.fullDesc <> Opt.progDesc "Update packages in nixpkgs repository" <>
|
|
|
|
Opt.header "nixpkgs-update")
|
2018-03-31 06:07:46 +03:00
|
|
|
|
2018-07-11 05:30:34 +03:00
|
|
|
makeOptions :: IO Options
|
2018-03-31 06:07:46 +03:00
|
|
|
makeOptions = do
|
2018-07-11 05:30:34 +03:00
|
|
|
dryRun <- isJust <$> getEnv "DRY_RUN"
|
2018-07-11 06:07:04 +03:00
|
|
|
homeDir <- T.pack <$> getHomeDirectory
|
2018-07-11 05:30:34 +03:00
|
|
|
githubToken <- T.strip <$> T.readFile "github_token.txt"
|
2018-07-11 06:07:04 +03:00
|
|
|
return $ Options dryRun (homeDir <> "/.nixpkgs-update") githubToken
|
2018-03-31 06:07:46 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
2018-07-11 05:30:34 +03:00
|
|
|
main = do
|
|
|
|
mode <- Opt.execParser programInfo
|
|
|
|
options <- makeOptions
|
2018-12-02 06:59:55 +03:00
|
|
|
setupNixpkgs
|
2018-07-11 05:30:34 +03:00
|
|
|
case mode of
|
2018-09-06 16:47:09 +03:00
|
|
|
DeleteDone -> deleteDone options
|
2018-07-11 05:30:34 +03:00
|
|
|
Update -> updateAll options
|