<commit_before>module Language.Docopt.Argument.Option (
    Flag ()
  , Name ()
  , OptionObj ()
  , OptionArgumentObj ()
  , IsOptional ()
  , IsRepeatable ()
  , showOptionObj
  , eqOptionObj
  , hasDefault
  , isFlag
  , takesArgument
  , prettyPrintOption
  , prettyPrintOptionNaked
  , empty
  , opt',   opt,   opt_,   optR,   optR_
  , lopt',  lopt,  lopt_,  loptR,  loptR_
  , sopt',  sopt,  sopt_,  soptR,  soptR_
  ,         optE,  optE_,  optER,  optER_
  , loptE', loptE, loptE_, loptER, loptER_
  , soptE', soptE, soptE_, soptER, soptER_
  ) where

import Prelude
import Data.Function (on)
import Control.Apply ((*>))
import Data.Maybe (Maybe(..), maybe)
import Data.Generic (class Generic, gEq, gShow)
import Data.String (fromChar)

import Language.Docopt.Value (Value(..), prettyPrintValue)

type Flag         = Char
type Name         = String
type IsRepeatable = Boolean
type IsOptional   = Boolean

type OptionObj =  { flag       :: Maybe Flag
                  , name       :: Maybe Name
                  , arg        :: Maybe OptionArgumentObj
                  , env        :: Maybe String
                  , repeatable :: IsRepeatable
                  }

showOptionObj :: OptionObj -> String
showOptionObj o = "{ flag: "       <> show o.flag
               <> ", name: "       <> show o.name
               <> ", arg: "        <> show (OptionArgument <$> o.arg)
               <> ", env: "        <> show o.env
               <> ", repeatable: " <> show o.repeatable
               <> "}"

eqOptionObj :: OptionObj -> OptionObj -> Boolean
eqOptionObj o o' = o.flag               == o'.flag
                && o.name               == o'.name
                && o.env                == o'.env
                && o.repeatable         == o'.repeatable
                && (OptionArgument <$> o.arg) == (OptionArgument <$> o'.arg)

newtype OptionArgument = OptionArgument OptionArgumentObj

unOptionArgument :: OptionArgument -> OptionArgumentObj
unOptionArgument (OptionArgument a) = a

instance showOptionArgument :: Show OptionArgument where
  show = showOptionArgumentObj <<< unOptionArgument

instance eqOptionArgument   :: Eq   OptionArgument where
  eq   = eqOptionArgumentObj `on` unOptionArgument

type OptionArgumentObj = { name     :: String
                   , default  :: Maybe Value
                   , optional :: Boolean
                   }

showOptionArgumentObj :: OptionArgumentObj -> String
showOptionArgumentObj a = "{ name: "     <> show a.name
                       <> ", default: "  <> show a.default
                       <> ", optional: " <> show a.optional
                       <> "}"

eqOptionArgumentObj :: OptionArgumentObj -> OptionArgumentObj -> Boolean
eqOptionArgumentObj a a' = a.name     == a'.name
                  && a.default  == a'.default
                  && a.optional == a'.optional

empty :: OptionObj
empty = { flag:       Nothing
        , name:       Nothing<commit_msg>Remove newtype wrapper: implement eq/show manually<commit_after>module Language.Docopt.Argument.Option (
    Flag ()
  , Name ()
  , OptionObj ()
  , OptionArgumentObj ()
  , IsOptional ()
  , IsRepeatable ()
  , showOptionObj
  , eqOptionObj
  , hasDefault
  , isFlag
  , takesArgument
  , prettyPrintOption
  , prettyPrintOptionNaked
  , empty
  , opt',   opt,   opt_,   optR,   optR_
  , lopt',  lopt,  lopt_,  loptR,  loptR_
  , sopt',  sopt,  sopt_,  soptR,  soptR_
  ,         optE,  optE_,  optER,  optER_
  , loptE', loptE, loptE_, loptER, loptER_
  , soptE', soptE, soptE_, soptER, soptER_
  ) where

import Prelude
import Data.Function (on)
import Control.Apply ((*>))
import Data.Maybe (Maybe(..), maybe)
import Data.Generic (class Generic, gEq, gShow)
import Data.String (fromChar)

import Language.Docopt.Value (Value(..), prettyPrintValue)

type Flag         = Char
type Name         = String
type IsRepeatable = Boolean
type IsOptional   = Boolean

type OptionObj =  { flag       :: Maybe Flag
                  , name       :: Maybe Name
                  , arg        :: Maybe OptionArgumentObj
                  , env        :: Maybe String
                  , repeatable :: IsRepeatable
                  }

showOptionObj :: OptionObj -> String
showOptionObj o = "{ flag: "       <> show o.flag
               <> ", name: "       <> show o.name
               <> ", arg: "        <> showArg o.arg
               <> ", env: "        <> show o.env
               <> ", repeatable: " <> show o.repeatable
               <> "}"
  where
    showArg (Just a) = showOptionArgumentObj a
    showArg Nothing  = "Nothing"

eqOptionObj :: OptionObj -> OptionObj -> Boolean
eqOptionObj o o' = o.flag       == o'.flag
                && o.name       == o'.name
                && o.env        == o'.env
                && o.repeatable == o'.repeatable
                && argsEqual o.arg o'.arg
  where
    argsEqual (Just a) (Just a') = eqOptionArgumentObj a a'
    argsEqual Nothing Nothing    = true
    argsEqual _ _                = false

type OptionArgumentObj = { name     :: String
                         , default  :: Maybe Value
                         , optional :: Boolean
                         }

showOptionArgumentObj :: OptionArgumentObj -> String
showOptionArgumentObj a = "{ name: "     <> show a.name
                       <> ", default: "  <> show a.default
                       <> ", optional: " <> show a.optional
                       <> "}"

eqOptionArgumentObj :: OptionArgumentObj -> OptionArgumentObj -> Boolean
eqOptionArgumentObj a a' = a.name     == a'.name
                  && a.default  == a'.default
                  && a.optional == a'.optional

empty :: OptionObj
empty = { flag:       Nothing
        , name:       Nothing
{'fraction_non_alphanumeric': 0.11245190626093039, 'fraction_numerical': 0.0, 'mean_word_length': 1.774866569626395, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 53, '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': '238466', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1610, 'n_words': 416}