packages feed

nix-thunk-0.1.0.0: src-bin/nix-thunk.hs

{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PackageImports #-}
import "nix-thunk" Nix.Thunk
import "nix-thunk" Nix.Thunk.Command
import Options.Applicative
import Cli.Extras
import qualified Data.Text.IO as T
import System.Environment
import System.Exit
import Data.Void

data Args = Args
  { _args_verbose :: Bool
  , _args_command :: ThunkOption
  }

verbose :: Parser Bool
verbose = flag False True $ mconcat
  [ long "verbose"
  , short 'v'
  , help "Produce more detailed output"
  ]

args :: Parser Args
args = Args <$> verbose <*> thunkOption

argsInfo :: ParserInfo Args
argsInfo = info (args <**> helper) $ mconcat
  [ fullDesc
  , progDesc "Manage source repositories using Nix"
  ]

parserPrefs :: ParserPrefs
parserPrefs = defaultPrefs
  { prefShowHelpOnEmpty = True
  }

main :: IO Void
main = do
  args <- getArgs
  args' <- handleParseResult $ execParserPure parserPrefs argsInfo args
  cliConf <- mkDefaultCliConfig args
  runCli cliConf (runThunkOption (_args_command args')) >>= \case
    Right () -> exitWith ExitSuccess
    Left e -> do
      T.putStrLn $ prettyNixThunkError e
      exitWith $ ExitFailure 2