diff options
author | slotThe <soliditsallgood@tuta.io> | 2020-01-04 21:20:56 +0100 |
---|---|---|
committer | jao <jao@gnu.org> | 2020-01-04 21:21:40 +0000 |
commit | 940be3bb32ed1f11c46ede98d51516998b17e128 (patch) | |
tree | 6d0c942c10efc64514dd419f746f631aec19c935 /src/Xmobar/Plugins/Monitors/Common | |
parent | 2ec513d2e193998958ad5bf4a5f7280f595792e9 (diff) | |
download | xmobar-940be3bb32ed1f11c46ede98d51516998b17e128.tar.gz xmobar-940be3bb32ed1f11c46ede98d51516998b17e128.tar.bz2 |
Replace parseOpts with a generic function
Diffstat (limited to 'src/Xmobar/Plugins/Monitors/Common')
-rw-r--r-- | src/Xmobar/Plugins/Monitors/Common/Parsers.hs | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/Xmobar/Plugins/Monitors/Common/Parsers.hs b/src/Xmobar/Plugins/Monitors/Common/Parsers.hs index 4b87a10..7a813e5 100644 --- a/src/Xmobar/Plugins/Monitors/Common/Parsers.hs +++ b/src/Xmobar/Plugins/Monitors/Common/Parsers.hs @@ -24,12 +24,14 @@ module Xmobar.Plugins.Monitors.Common.Parsers ( runP , skipTillString , parseTemplate , parseTemplate' + , parseOptsWith ) where import Xmobar.Plugins.Monitors.Common.Types import Control.Applicative ((<$>)) import qualified Data.Map as Map +import System.Console.GetOpt (ArgOrder(Permute), OptDescr, getOpt) import Text.ParserCombinators.Parsec runP :: Parser [a] -> String -> IO [a] @@ -150,3 +152,14 @@ combine m ((s,ts,ss):xs) = Nothing -> return $ "<" ++ ts ++ ">" Just r -> let f "" = r; f n = n; in f <$> parseTemplate' r m return $ s ++ str ++ ss ++ next + +-- | Try to parse arguments from the config file and apply them to Options. +parseOptsWith + :: [OptDescr (opts -> opts)] -- ^ Options that are specifiable + -> opts -- ^ Default options to use as a fallback + -> [String] -- ^ Actual arguments given + -> IO opts +parseOptsWith options defaultOpts argv = + case getOpt Permute options argv of + (o, _, [] ) -> pure $ foldr id defaultOpts o + (_, _, errs) -> ioError . userError $ concat errs |