<commit_before>
module System.Console.CmdArgs.Explicit.Help where

import System.Console.CmdArgs.Explicit.Type
import System.Console.CmdArgs.Text

instance Show (Mode a) where
    show = show . helpText


helpText :: Mode a -> [Text]
helpText _ = [Line "Help output"]<commit_msg>Implement the Help feature for Explicit<commit_after>
module System.Console.CmdArgs.Explicit.Help where

import System.Console.CmdArgs.Explicit.Type
import System.Console.CmdArgs.Text
import Data.List

instance Show (Mode a) where
    show = show . helpText


helpText :: Mode a -> [Text]
helpText m = helpGroup helpMode (modeGroupList m) ++
            [Line "" | null $ modeList m] ++
            helpGroup helpFlag (modeGroupFlags m)


helpGroup :: (a -> [Text]) -> Group a -> [Text]
helpGroup f xs = concat [[Line x | x /= ""] ++ concatMap f y | (x,y) <- xs]


helpMode :: ([Name],Mode a) -> [Text]
helpMode (xs,y) = [Cols [commas xs, modeHelp y]]


helpFlag :: Flag a -> [Text]
helpFlag x = case flagInfo x of
    FlagUnnamed -> []
    FlagNamed typ names -> [Cols [commas $ map ("-"++) a2, commas $ map ("--"++) b2, flagHelp x]]
        where
            (a,b) = partition ((==) 1 . length) names
            (a2,b2) = if null b then (add a opt, b) else (a, add b opt)
            add x y = if null x then x else (head x ++ y) : tail x
            hlp = if null (flagType x) then "ITEM" else flagType x
            opt = case typ of
                ArgReq -> '=' : hlp
                ArgOpt x -> "[=" ++ hlp ++ "]"
                _ -> ""


commas = intercalate ", "
{'fraction_non_alphanumeric': 0.13981958762886598, 'fraction_numerical': 0.0032216494845360823, 'mean_word_length': 2.458797327394209, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 15, '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': '3505067', 'n_tokens_mistral': 515, 'n_tokens_neox': 497, 'n_words': 171}