module System.Console.CmdArgs.GetOpt(
convert, getOpt, getOpt', usageInfo,
ArgOrder(..), OptDescr(..), ArgDescr(..)
) where
import System.Console.CmdArgs.Explicit
import System.Console.GetOpt(OptDescr(..), ArgDescr(..))
data ArgOrder a = Permute
instance Functor ArgOrder where
fmap :: forall a b. (a -> b) -> ArgOrder a -> ArgOrder b
fmap a -> b
_ ArgOrder a
Permute = forall a. ArgOrder a
Permute
usageInfo :: String -> [OptDescr a] -> String
usageInfo :: forall a. String -> [OptDescr a] -> String
usageInfo String
desc [OptDescr a]
flags = [String] -> String
unlines forall a b. (a -> b) -> a -> b
$ String
desc forall a. a -> [a] -> [a]
: forall a. Int -> [a] -> [a]
drop Int
2 (String -> [String]
lines forall a b. (a -> b) -> a -> b
$ forall a. Show a => a -> String
show forall a b. (a -> b) -> a -> b
$ forall a. String -> [OptDescr a] -> Mode ([a], [String])
convert String
"" [OptDescr a]
flags)
getOpt :: ArgOrder a -> [OptDescr a] -> [String] -> ([a], [String], [String])
getOpt :: forall a.
ArgOrder a -> [OptDescr a] -> [String] -> ([a], [String], [String])
getOpt ArgOrder a
_ [OptDescr a]
flags [String]
args =
case forall a. Mode a -> [String] -> Either String a
process (forall a. String -> [OptDescr a] -> Mode ([a], [String])
convert String
"" [OptDescr a]
flags) [String]
args of
Left String
x -> ([],[],[String
x])
Right ([a]
a,[String]
b) -> ([a]
a,[String]
b,[])
getOpt' :: ArgOrder a -> [OptDescr a] -> [String] -> ([a], [String], [String], [String])
getOpt' :: forall a.
ArgOrder a
-> [OptDescr a] -> [String] -> ([a], [String], [String], [String])
getOpt' ArgOrder a
x [OptDescr a]
y [String]
z = ([a]
a,[String]
b,[],[String]
c)
where ([a]
a,[String]
b,[String]
c) = forall a.
ArgOrder a -> [OptDescr a] -> [String] -> ([a], [String], [String])
getOpt ArgOrder a
x [OptDescr a]
y [String]
z
convert :: String -> [OptDescr a] -> Mode ([a],[String])
convert :: forall a. String -> [OptDescr a] -> Mode ([a], [String])
convert String
help [OptDescr a]
flags = forall a. String -> a -> String -> Arg a -> [Flag a] -> Mode a
mode String
"program" ([],[]) String
help forall {a}. Arg (a, [String])
args (forall a b. (a -> b) -> [a] -> [b]
map forall {a} {b}. OptDescr a -> Flag ([a], b)
f [OptDescr a]
flags)
where
args :: Arg (a, [String])
args = forall a. Update a -> String -> Arg a
flagArg (\String
x (a
a,[String]
b) -> forall a b. b -> Either a b
Right (a
a,[String]
bforall a. [a] -> [a] -> [a]
++[String
x])) String
"ARG"
f :: OptDescr a -> Flag ([a], b)
f (Option String
short [String]
long ArgDescr a
x String
help) = case ArgDescr a
x of
NoArg a
x -> forall a. [String] -> (a -> a) -> String -> Flag a
flagNone [String]
names (\([a]
a,b
b) -> ([a]
aforall a. [a] -> [a] -> [a]
++[a
x],b
b)) String
help
ReqArg String -> a
op String
x -> forall a. [String] -> Update a -> String -> String -> Flag a
flagReq [String]
names (\String
x ([a]
a,b
b) -> forall a b. b -> Either a b
Right ([a]
aforall a. [a] -> [a] -> [a]
++[String -> a
op String
x],b
b)) String
x String
help
OptArg Maybe String -> a
op String
x -> forall a.
String -> [String] -> Update a -> String -> String -> Flag a
flagOpt String
"" [String]
names (\String
x ([a]
a,b
b) -> forall a b. b -> Either a b
Right ([a]
aforall a. [a] -> [a] -> [a]
++[Maybe String -> a
op forall a b. (a -> b) -> a -> b
$ if forall (t :: * -> *) a. Foldable t => t a -> Bool
null String
x then forall a. Maybe a
Nothing else forall a. a -> Maybe a
Just String
x],b
b)) String
x String
help
where names :: [String]
names = forall a b. (a -> b) -> [a] -> [b]
map forall (m :: * -> *) a. Monad m => a -> m a
return String
short forall a. [a] -> [a] -> [a]
++ [String]
long