<commit_before>
module CmdLine(Mode(..), getMode) where

import Control.Monad
import Data.List
import System.Console.GetOpt
import System.Directory
import System.Environment
import System.Exit
import System.FilePath


data Mode = Mode
    {modeHints :: [FilePath]  -- ^ which hint files to use
    ,modeFiles :: [FilePath]  -- ^ which files to run it on
    ,modeTest :: Bool         -- ^ run in test mode?
    }


data Opts = Help | HintFile FilePath | Test
            deriving Eq

opts = [Option "?" ["help"] (NoArg Help) "Display help message"
       ,Option "h" ["hint"] (ReqArg HintFile "file") "Hint file to use"
       ,Option "t" ["test"] (NoArg Test) "Run in test mode"
       ]


-- | Exit out if you need to display help info
getMode :: IO Mode
getMode = do
    args <- getArgs
    let (opt,files,err) = getOpt Permute opts args
    when (not $ null err) $
        error $ unlines $ "Unrecognised arguments:" : err

    when (Help `elem` opt || null files) $ do
        putStr $ unlines ["Dr Haskell, (C) <NAME> 2006-2008, University of York"
                         ,usageInfo "" opts
                         ,"Dr Haskell makes hints on how to improve some Haskell code."]
        exitWith ExitSuccess

    hints <- return [x | HintFile x <- opt]
    hints <- return $ if null hints then ["Hints.hs"] else hints

    let test = Test `elem` opt
    files <- liftM concat $ mapM getFile files
    return Mode{modeHints=hints, modeFiles=files, modeTest=test}


getFile :: FilePath -> IO [FilePath]
getFile file = do
    b <- doesDirectoryExist file
    if not b then return [file] else f file
    where
        f file | takeExtension file `elem` [".hs",".lhs"] = return [file]
        f file = do
            b <- doesDirectoryExist file<commit_msg>Reformat the --help script a little<commit_after>
module CmdLine(Mode(..), getMode) where

import Control.Monad
import Data.List
import System.Console.GetOpt
import System.Directory
import System.Environment
import System.Exit
import System.FilePath


data Mode = Mode
    {modeHints :: [FilePath]  -- ^ which hint files to use
    ,modeFiles :: [FilePath]  -- ^ which files to run it on
    ,modeTest :: Bool         -- ^ run in test mode?
    }


data Opts = Help | HintFile FilePath | Test
            deriving Eq

opts = [Option "?" ["help"] (NoArg Help) "Display help message"
       ,Option "h" ["hint"] (ReqArg HintFile "file") "Hint file to use"
       ,Option "t" ["test"] (NoArg Test) "Run in test mode"
       ]


-- | Exit out if you need to display help info
getMode :: IO Mode
getMode = do
    args <- getArgs
    let (opt,files,err) = getOpt Permute opts args
    when (not $ null err) $
        error $ unlines $ "Unrecognised arguments:" : err

    when (Help `elem` opt || null files) $ do
        putStr $ unlines ["Dr Haskell, (C) <NAME> 2006-2008, University of York"
                         ,""
                         ,"  drhaskell [files] [options]"
                         ,usageInfo "" opts
                         ,"Dr Haskell makes hints on how to improve some Haskell code."]
        exitWith ExitSuccess

    hints <- return [x | HintFile x <- opt]
    hints <- return $ if null hints then ["Hints.hs"] else hints

    let test = Test `elem` opt
    files <- liftM concat $ mapM getFile files
    return Mode{modeHints=hints, modeFiles=files, modeTest=test}


getFile :: FilePath -> IO [FilePath]
getFile file = do
    b <- doesDirectoryExist file
    if not b then return [file] else f file
    where
        f file | takeExtension file `elem` [".hs",".lhs"] = return [file]
        f file = do
            b <- doesDirectoryExist file
{'fraction_non_alphanumeric': 0.10795923987882126, 'fraction_numerical': 0.004406499586890664, 'mean_word_length': 2.381750465549348, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2679773', 'n_tokens_mistral': 1129, 'n_tokens_neox': 1056, 'n_words': 417}