nixpkgs-update/src/Main.hs

57 lines
1.6 KiB
Haskell
Raw Normal View History

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 ((<**>), (<|>))
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
= Update
2018-04-04 02:03:46 +03:00
| DeleteMerged
modeParser :: Opt.Parser Mode
modeParser =
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" )
programInfo :: Opt.ParserInfo Mode
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
dryRun <- isJust <$> get_env "DRY_RUN"
2018-04-04 11:19:09 +03:00
workingDir <- (</> ".nixpkgs-update") <$> get_env_text "HOME"
2018-04-04 13:24:30 +03:00
githubToken <- T.strip <$> readfile "github_token.txt"
2018-04-03 02:12:55 +03:00
return $ Options dryRun workingDir githubToken
setUpEnvironment :: Options -> Sh ()
setUpEnvironment options = do
setenv "PAGER" ""
setenv "GITHUB_TOKEN" (githubToken options)
2018-03-31 06:07:46 +03:00
main :: IO ()
2018-04-04 18:28:15 +03:00
main = shelly $ verbosely $ do
2018-04-04 02:03:46 +03:00
mode <- liftIO $ Opt.execParser programInfo
2018-04-03 01:46:38 +03:00
2018-04-04 02:03:46 +03:00
options <- makeOptions
2018-03-31 06:07:46 +03:00
2018-04-03 02:12:55 +03:00
setUpEnvironment options
2018-03-31 06:07:46 +03:00
2018-04-04 02:03:46 +03:00
case mode of
DeleteMerged -> deleteMerged
Update -> updateAll options