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-04-04 02:03:46 +03:00
|
|
|
import DeleteMerged (deleteMerged)
|
|
|
|
import qualified Options.Applicative as Opt
|
2018-04-04 12:24:55 +03:00
|
|
|
import Shelly
|
|
|
|
import Update (updateAll)
|
|
|
|
import Utils (Options(..))
|
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
|
|
|
|
| DeleteMerged
|
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'
|
|
|
|
DeleteMerged
|
|
|
|
(Opt.long "delete-merged" <>
|
|
|
|
Opt.help "Delete branches that were already merged")
|
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
|
|
|
|
|
|
|
makeOptions :: Sh Options
|
|
|
|
makeOptions = do
|
2018-04-06 18:17:22 +03:00
|
|
|
dryRun <- isJust <$> get_env "DRY_RUN"
|
|
|
|
workingDir <- (</> ".nixpkgs-update") <$> get_env_text "HOME"
|
|
|
|
githubToken <- T.strip <$> readfile "github_token.txt"
|
|
|
|
return $ Options dryRun workingDir githubToken
|
2018-04-03 02:12:55 +03:00
|
|
|
|
2018-04-06 18:36:05 +03:00
|
|
|
-- | Set environment variables needed by various programs
|
2018-04-03 02:12:55 +03:00
|
|
|
setUpEnvironment :: Options -> Sh ()
|
|
|
|
setUpEnvironment options = do
|
2018-04-06 18:17:22 +03:00
|
|
|
setenv "PAGER" ""
|
|
|
|
setenv "GITHUB_TOKEN" (githubToken options)
|
2018-03-31 06:07:46 +03:00
|
|
|
|
|
|
|
main :: IO ()
|
2018-04-06 18:17:22 +03:00
|
|
|
main =
|
|
|
|
shelly $
|
|
|
|
verbosely $ do
|
2018-04-04 02:03:46 +03:00
|
|
|
mode <- liftIO $ Opt.execParser programInfo
|
|
|
|
options <- makeOptions
|
2018-04-03 02:12:55 +03:00
|
|
|
setUpEnvironment options
|
2018-04-04 02:03:46 +03:00
|
|
|
case mode of
|
2018-04-06 18:17:22 +03:00
|
|
|
DeleteMerged -> deleteMerged
|
|
|
|
Update -> updateAll options
|