<commit_before>{-# LANGUAGE RecordWildCards #-}
import           Stackage.Types
import           Stackage.Build     (build, defaultBuildSettings)
import           Stackage.Init      (stackageInit)
import           System.Environment (getArgs, getProgName)
import           Data.Set           (fromList)

data BuildArgs = BuildArgs
    { noClean :: Bool
    , excluded :: [String]
    }

parseBuildArgs :: [String] -> IO BuildArgs
parseBuildArgs =
    loop $ BuildArgs False []
  where
    loop x [] = return x
    loop x ("--no-clean":rest) = loop x { noClean = True } rest
    loop x ("--exclude":y:rest) = loop x { excluded = y : excluded x } rest
    loop _ (y:_) = error $ "Did not understand argument: " ++ y

main :: IO ()
main = do
    args <- getArgs
    case args of
        "build":rest -> do
            BuildArgs {..} <- parseBuildArgs rest
            build defaultBuildSettings
                { cleanBeforeBuild = not noClean
                , excludedPackages = fromList $ map PackageName excluded
                }
        ["init"] -> stackageInit
        ["update"] -> stackageInit >> error "FIXME update"
        _ -> do
            pn <- getProgName
            putStrLn $ "Usage: " ++ pn ++ " <command>"
            putStrLn "Available commands:"
            putStrLn "    update              Download updated Stackage databases. Automatically calls init."
            putStrLn "    init                Initialize your cabal file to use Stackage"
            putStrLn "    build [--no-clean] [--exclude package...]"
            putStrLn "                        Build the package databases (maintainers only)"<commit_msg>Add a scary warning about init<commit_after>{-# LANGUAGE RecordWildCards #-}
import           Stackage.Types
import           Stackage.Build     (build, defaultBuildSettings)
import           Stackage.Init      (stackageInit)
import           System.Environment (getArgs, getProgName)
import           Data.Set           (fromList)
import           System.IO          (hFlush, stdout)

data BuildArgs = BuildArgs
    { noClean :: Bool
    , excluded :: [String]
    }

parseBuildArgs :: [String] -> IO BuildArgs
parseBuildArgs =
    loop $ BuildArgs False []
  where
    loop x [] = return x
    loop x ("--no-clean":rest) = loop x { noClean = True } rest
    loop x ("--exclude":y:rest) = loop x { excluded = y : excluded x } rest
    loop _ (y:_) = error $ "Did not understand argument: " ++ y

main :: IO ()
main = do
    args <- getArgs
    case args of
        "build":rest -> do
            BuildArgs {..} <- parseBuildArgs rest
            build defaultBuildSettings
                { cleanBeforeBuild = not noClean
                , excludedPackages = fromList $ map PackageName excluded
                }
        ["init"] -> do
            putStrLn "Note: init isn't really ready for prime time use."
            putStrLn "Using it may make it impossible to build stackage."
            putStr "Are you sure you want continue (y/n)? "
            hFlush stdout
            x <- getLine
            case x of
                c:_ | c `elem` "yY" -> stackageInit
                _ -> putStrLn "Probably a good decision, exiting."
        ["update"] -> stackageInit >> error "FIXME update"
        _ -> do
            pn <- getProgName
            putStrLn $ "Usage: " ++ pn ++ " <command>"
            putStrLn "Available commands:"
            putStrLn "    update              Download updated Stackage databases. Automatically calls init."
            putStrLn "    init                Initialize your cabal file to use Stackage"
            putStrLn "    build [--no-clean] [--exclude package...]"
            putStrLn "                        Build the package databases (maintainers only)"
{'fraction_non_alphanumeric': 0.09724819663371627, 'fraction_numerical': 0.0, 'mean_word_length': 1.7468818782098312, 'pattern_counts': {'":': 6, '<': 12, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2829498', 'n_tokens_mistral': 1026, 'n_tokens_neox': 987, 'n_words': 326}