Fix commandline flag parsing (again, oops)
parent
59cee6fb0e
commit
b58a8b0146
|
@ -219,7 +219,7 @@ mainCmdParser = do
|
||||||
then trace "----"
|
then trace "----"
|
||||||
else id
|
else id
|
||||||
|
|
||||||
readConfigs :: ConfigF Maybe -> [System.IO.FilePath] -> MaybeT IO Config
|
readConfigs :: ConfigF Option -> [System.IO.FilePath] -> MaybeT IO Config
|
||||||
readConfigs cmdlineConfig configPaths = do
|
readConfigs cmdlineConfig configPaths = do
|
||||||
let defLocalConfigPath = "brittany.yaml"
|
let defLocalConfigPath = "brittany.yaml"
|
||||||
userBritPath <- liftIO $ Directory.getAppUserDataDirectory "brittany"
|
userBritPath <- liftIO $ Directory.getAppUserDataDirectory "brittany"
|
||||||
|
@ -234,4 +234,4 @@ readConfigs cmdlineConfig configPaths = do
|
||||||
paths -> foldl (\prev p -> prev >>= readMergePersConfig p False)
|
paths -> foldl (\prev p -> prev >>= readMergePersConfig p False)
|
||||||
(return cmdlineConfig)
|
(return cmdlineConfig)
|
||||||
paths
|
paths
|
||||||
return $ cZip fromMaybeIdentity staticDefaultConfig merged
|
return $ cZip fromOptionIdentity staticDefaultConfig merged
|
||||||
|
|
|
@ -70,7 +70,7 @@ import Data.Coerce ( Coercible, coerce )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
configParser :: CmdParser Identity out (ConfigF Maybe)
|
configParser :: CmdParser Identity out (ConfigF Option)
|
||||||
configParser = do
|
configParser = do
|
||||||
-- TODO: why does the default not trigger; ind never should be []!!
|
-- TODO: why does the default not trigger; ind never should be []!!
|
||||||
ind <- addFlagReadParam "" ["indent"] "AMOUNT"
|
ind <- addFlagReadParam "" ["indent"] "AMOUNT"
|
||||||
|
@ -112,18 +112,18 @@ configParser = do
|
||||||
, _dconf_dump_bridoc_final = wrapLast $ falseToNothing dumpBriDocFinal
|
, _dconf_dump_bridoc_final = wrapLast $ falseToNothing dumpBriDocFinal
|
||||||
}
|
}
|
||||||
, _conf_layout = LayoutConfig
|
, _conf_layout = LayoutConfig
|
||||||
{ _lconfig_cols = listLastMaybe cols
|
{ _lconfig_cols = optionConcat cols
|
||||||
, _lconfig_indentPolicy = Nothing
|
, _lconfig_indentPolicy = mempty
|
||||||
, _lconfig_indentAmount = listLastMaybe ind
|
, _lconfig_indentAmount = optionConcat ind
|
||||||
, _lconfig_indentWhereSpecial = Nothing -- falseToNothing _
|
, _lconfig_indentWhereSpecial = mempty -- falseToNothing _
|
||||||
, _lconfig_indentListSpecial = Nothing -- falseToNothing _
|
, _lconfig_indentListSpecial = mempty -- falseToNothing _
|
||||||
, _lconfig_importColumn = listLastMaybe importCol
|
, _lconfig_importColumn = optionConcat importCol
|
||||||
, _lconfig_altChooser = Nothing
|
, _lconfig_altChooser = mempty
|
||||||
}
|
}
|
||||||
, _conf_errorHandling = ErrorHandlingConfig
|
, _conf_errorHandling = ErrorHandlingConfig
|
||||||
{ _econf_produceOutputOnErrors = wrapLast $ falseToNothing outputOnErrors
|
{ _econf_produceOutputOnErrors = wrapLast $ falseToNothing outputOnErrors
|
||||||
, _econf_Werror = wrapLast $ falseToNothing wError
|
, _econf_Werror = wrapLast $ falseToNothing wError
|
||||||
, _econf_CPPMode = Nothing
|
, _econf_CPPMode = mempty
|
||||||
}
|
}
|
||||||
, _conf_forward = ForwardOptions
|
, _conf_forward = ForwardOptions
|
||||||
{ _options_ghc = [ optionsGhc & List.unwords & CmdArgs.splitArgs
|
{ _options_ghc = [ optionsGhc & List.unwords & CmdArgs.splitArgs
|
||||||
|
@ -131,9 +131,12 @@ configParser = do
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
where falseToNothing = Bool.bool Nothing (Just True)
|
where falseToNothing = Option . Bool.bool Nothing (Just True)
|
||||||
|
wrapLast :: Option a -> Option (Semigroup.Last a)
|
||||||
wrapLast = fmap Semigroup.Last
|
wrapLast = fmap Semigroup.Last
|
||||||
listLastMaybe = listToMaybe . reverse
|
optionConcat
|
||||||
|
:: (Semigroup.Semigroup (f a), Applicative f) => [a] -> Option (f a)
|
||||||
|
optionConcat = mconcat . fmap (pure . pure)
|
||||||
|
|
||||||
-- configParser :: Parser Config
|
-- configParser :: Parser Config
|
||||||
-- configParser = Config
|
-- configParser = Config
|
||||||
|
@ -157,7 +160,7 @@ configParser = do
|
||||||
-- }
|
-- }
|
||||||
|
|
||||||
readMergePersConfig
|
readMergePersConfig
|
||||||
:: System.IO.FilePath -> Bool -> ConfigF Maybe -> MaybeT IO (ConfigF Maybe)
|
:: System.IO.FilePath -> Bool -> ConfigF Option -> MaybeT IO (ConfigF Option)
|
||||||
readMergePersConfig path shouldCreate conf = do
|
readMergePersConfig path shouldCreate conf = do
|
||||||
exists <- liftIO $ System.Directory.doesFileExist path
|
exists <- liftIO $ System.Directory.doesFileExist path
|
||||||
if
|
if
|
||||||
|
@ -175,7 +178,7 @@ readMergePersConfig path shouldCreate conf = do
|
||||||
| shouldCreate -> do
|
| shouldCreate -> do
|
||||||
liftIO $ ByteString.writeFile path
|
liftIO $ ByteString.writeFile path
|
||||||
$ Data.Yaml.encode
|
$ Data.Yaml.encode
|
||||||
$ cMap (Just . runIdentity) staticDefaultConfig
|
$ cMap (Option . Just . runIdentity) staticDefaultConfig
|
||||||
return $ conf
|
return $ conf
|
||||||
| otherwise -> do
|
| otherwise -> do
|
||||||
return conf
|
return conf
|
||||||
|
@ -183,4 +186,4 @@ readMergePersConfig path shouldCreate conf = do
|
||||||
showConfigYaml :: Config -> String
|
showConfigYaml :: Config -> String
|
||||||
showConfigYaml = Data.ByteString.Char8.unpack
|
showConfigYaml = Data.ByteString.Char8.unpack
|
||||||
. Data.Yaml.encode
|
. Data.Yaml.encode
|
||||||
. cMap (\(Identity x) -> Just x)
|
. cMap (\(Identity x) -> Option (Just x))
|
||||||
|
|
|
@ -21,7 +21,7 @@ import Data.Coerce ( Coercible, coerce )
|
||||||
|
|
||||||
import Data.Semigroup.Generic
|
import Data.Semigroup.Generic
|
||||||
|
|
||||||
import Data.Semigroup ( Last )
|
import Data.Semigroup ( Last, Option )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -83,11 +83,11 @@ deriving instance Show (ErrorHandlingConfigF Identity)
|
||||||
deriving instance Show (ForwardOptionsF Identity)
|
deriving instance Show (ForwardOptionsF Identity)
|
||||||
deriving instance Show (ConfigF Identity)
|
deriving instance Show (ConfigF Identity)
|
||||||
|
|
||||||
deriving instance Show (DebugConfigF Maybe)
|
deriving instance Show (DebugConfigF Option)
|
||||||
deriving instance Show (LayoutConfigF Maybe)
|
deriving instance Show (LayoutConfigF Option)
|
||||||
deriving instance Show (ErrorHandlingConfigF Maybe)
|
deriving instance Show (ErrorHandlingConfigF Option)
|
||||||
deriving instance Show (ForwardOptionsF Maybe)
|
deriving instance Show (ForwardOptionsF Option)
|
||||||
deriving instance Show (ConfigF Maybe)
|
deriving instance Show (ConfigF Option)
|
||||||
|
|
||||||
deriving instance Data (DebugConfigF Identity)
|
deriving instance Data (DebugConfigF Identity)
|
||||||
deriving instance Data (LayoutConfigF Identity)
|
deriving instance Data (LayoutConfigF Identity)
|
||||||
|
@ -95,15 +95,15 @@ deriving instance Data (ErrorHandlingConfigF Identity)
|
||||||
deriving instance Data (ForwardOptionsF Identity)
|
deriving instance Data (ForwardOptionsF Identity)
|
||||||
deriving instance Data (ConfigF Identity)
|
deriving instance Data (ConfigF Identity)
|
||||||
|
|
||||||
instance Semigroup.Semigroup (DebugConfigF Maybe) where
|
instance Semigroup.Semigroup (DebugConfigF Option) where
|
||||||
(<>) = gmappend
|
(<>) = gmappend
|
||||||
instance Semigroup.Semigroup (LayoutConfigF Maybe) where
|
instance Semigroup.Semigroup (LayoutConfigF Option) where
|
||||||
(<>) = gmappend
|
(<>) = gmappend
|
||||||
instance Semigroup.Semigroup (ErrorHandlingConfigF Maybe) where
|
instance Semigroup.Semigroup (ErrorHandlingConfigF Option) where
|
||||||
(<>) = gmappend
|
(<>) = gmappend
|
||||||
instance Semigroup.Semigroup (ForwardOptionsF Maybe) where
|
instance Semigroup.Semigroup (ForwardOptionsF Option) where
|
||||||
(<>) = gmappend
|
(<>) = gmappend
|
||||||
instance Semigroup.Semigroup (ConfigF Maybe) where
|
instance Semigroup.Semigroup (ConfigF Option) where
|
||||||
(<>) = gmappend
|
(<>) = gmappend
|
||||||
|
|
||||||
type Config = ConfigF Identity
|
type Config = ConfigF Identity
|
||||||
|
@ -116,9 +116,17 @@ instance FromJSON a => FromJSON (Semigroup.Last a) where
|
||||||
{-# INLINE parseJSON #-}
|
{-# INLINE parseJSON #-}
|
||||||
instance ToJSON a => ToJSON (Semigroup.Last a) where
|
instance ToJSON a => ToJSON (Semigroup.Last a) where
|
||||||
toJSON (Semigroup.Last x) = toJSON x
|
toJSON (Semigroup.Last x) = toJSON x
|
||||||
|
{-# INLINE toJSON #-}
|
||||||
|
|
||||||
instance FromJSON (DebugConfigF Maybe)
|
instance FromJSON a => FromJSON (Option a) where
|
||||||
instance ToJSON (DebugConfigF Maybe)
|
parseJSON obj = Option <$> parseJSON obj
|
||||||
|
{-# INLINE parseJSON #-}
|
||||||
|
instance ToJSON a => ToJSON (Option a) where
|
||||||
|
toJSON (Option x) = toJSON x
|
||||||
|
{-# INLINE toJSON #-}
|
||||||
|
|
||||||
|
instance FromJSON (DebugConfigF Option)
|
||||||
|
instance ToJSON (DebugConfigF Option)
|
||||||
|
|
||||||
instance FromJSON IndentPolicy
|
instance FromJSON IndentPolicy
|
||||||
instance ToJSON IndentPolicy
|
instance ToJSON IndentPolicy
|
||||||
|
@ -127,17 +135,17 @@ instance ToJSON AltChooser
|
||||||
instance FromJSON CPPMode
|
instance FromJSON CPPMode
|
||||||
instance ToJSON CPPMode
|
instance ToJSON CPPMode
|
||||||
|
|
||||||
instance FromJSON (LayoutConfigF Maybe)
|
instance FromJSON (LayoutConfigF Option)
|
||||||
instance ToJSON (LayoutConfigF Maybe)
|
instance ToJSON (LayoutConfigF Option)
|
||||||
|
|
||||||
instance FromJSON (ErrorHandlingConfigF Maybe)
|
instance FromJSON (ErrorHandlingConfigF Option)
|
||||||
instance ToJSON (ErrorHandlingConfigF Maybe)
|
instance ToJSON (ErrorHandlingConfigF Option)
|
||||||
|
|
||||||
instance FromJSON (ForwardOptionsF Maybe)
|
instance FromJSON (ForwardOptionsF Option)
|
||||||
instance ToJSON (ForwardOptionsF Maybe)
|
instance ToJSON (ForwardOptionsF Option)
|
||||||
|
|
||||||
instance FromJSON (ConfigF Maybe)
|
instance FromJSON (ConfigF Option)
|
||||||
instance ToJSON (ConfigF Maybe)
|
instance ToJSON (ConfigF Option)
|
||||||
|
|
||||||
-- instance Monoid DebugConfig where
|
-- instance Monoid DebugConfig where
|
||||||
-- mempty = DebugConfig Nothing Nothing
|
-- mempty = DebugConfig Nothing Nothing
|
||||||
|
|
|
@ -6,6 +6,7 @@ module Language.Haskell.Brittany.Utils
|
||||||
, (%=+)
|
, (%=+)
|
||||||
, parDoc
|
, parDoc
|
||||||
, fromMaybeIdentity
|
, fromMaybeIdentity
|
||||||
|
, fromOptionIdentity
|
||||||
, traceIfDumpConf
|
, traceIfDumpConf
|
||||||
, mModify
|
, mModify
|
||||||
, customLayouterF
|
, customLayouterF
|
||||||
|
@ -78,6 +79,11 @@ fromMaybeIdentity :: Identity a -> Maybe a -> Identity a
|
||||||
fromMaybeIdentity x y = Data.Coerce.coerce
|
fromMaybeIdentity x y = Data.Coerce.coerce
|
||||||
$ fromMaybe (Data.Coerce.coerce x) y
|
$ fromMaybe (Data.Coerce.coerce x) y
|
||||||
|
|
||||||
|
fromOptionIdentity :: Identity a -> Option a -> Identity a
|
||||||
|
fromOptionIdentity x y = Data.Coerce.coerce
|
||||||
|
$ fromMaybe (Data.Coerce.coerce x)
|
||||||
|
$ getOption y
|
||||||
|
|
||||||
-- maximum monoid over N+0
|
-- maximum monoid over N+0
|
||||||
-- or more than N, because Num is allowed.
|
-- or more than N, because Num is allowed.
|
||||||
newtype Max a = Max { getMax :: a }
|
newtype Max a = Max { getMax :: a }
|
||||||
|
|
|
@ -445,6 +445,7 @@ import Data.Char ( Char )
|
||||||
import Data.Either ( Either(..) )
|
import Data.Either ( Either(..) )
|
||||||
import Data.IORef ( IORef )
|
import Data.IORef ( IORef )
|
||||||
import Data.Maybe ( Maybe(..) )
|
import Data.Maybe ( Maybe(..) )
|
||||||
|
import Data.Semigroup ( Option(..) )
|
||||||
import Data.Monoid ( Endo(..), All(..), Any(..), Sum(..), Product(..), Alt(..), )
|
import Data.Monoid ( Endo(..), All(..), Any(..), Sum(..), Product(..), Alt(..), )
|
||||||
import Data.Ord ( Ordering(..), Down(..) )
|
import Data.Ord ( Ordering(..), Down(..) )
|
||||||
import Data.Ratio ( Ratio, Rational )
|
import Data.Ratio ( Ratio, Rational )
|
||||||
|
|
Loading…
Reference in New Issue