diff options
author | Joe Crayne <joe@jerkface.net> | 2019-07-11 22:17:09 -0400 |
---|---|---|
committer | Joe Crayne <joe@jerkface.net> | 2019-07-11 22:17:09 -0400 |
commit | 365bdcd8d9f4a08aaae35fc27722d268f4af9041 (patch) | |
tree | acc5aa18e90eb7f90174ca172136e49198495fbd /lib/CommandLine.hs | |
parent | a2cfd42e569e2f8d0a7011573f72ba0876ae16e8 (diff) |
WIP: verify command to verify clear-sign PGP signatures.
Diffstat (limited to 'lib/CommandLine.hs')
-rw-r--r-- | lib/CommandLine.hs | 38 |
1 files changed, 27 insertions, 11 deletions
diff --git a/lib/CommandLine.hs b/lib/CommandLine.hs index ea5d6b8..2676260 100644 --- a/lib/CommandLine.hs +++ b/lib/CommandLine.hs | |||
@@ -14,6 +14,8 @@ module CommandLine | |||
14 | , fancy | 14 | , fancy |
15 | , runArgs | 15 | , runArgs |
16 | , arg | 16 | , arg |
17 | , args | ||
18 | , flag | ||
17 | , param | 19 | , param |
18 | , params | 20 | , params |
19 | , label | 21 | , label |
@@ -50,11 +52,11 @@ type MergeData = [(Int,Ordering)] | |||
50 | data Expr a where | 52 | data Expr a where |
51 | -- Prim | 53 | -- Prim |
52 | -- | 54 | -- |
53 | -- Takes a function from the option arguments and unamed arguments repsectively to | 55 | -- Takes a function from the option arguments and unnamed arguments |
54 | -- a value of type a, usually IO (), and gives you an expression tree. As one | 56 | -- respectively to a value of type a, usually IO (), and gives you an |
55 | -- traverses down the tree only the 'interesting' option arguments are passed | 57 | -- expression tree. As one traverses down the tree only the 'interesting' |
56 | -- to this function, but all of the unnamed arguments are passed regardless of | 58 | -- option arguments are passed to this function, but all of the unnamed |
57 | -- where we are in the tree. | 59 | -- arguments are passed regardless of where we are in the tree. |
58 | -- | 60 | -- |
59 | Prim :: ([[String]] -> [String] -> a) -> Interval (SuperOrd Int) -> Expr a | 61 | Prim :: ([[String]] -> [String] -> a) -> Interval (SuperOrd Int) -> Expr a |
60 | -- Star | 62 | -- Star |
@@ -233,17 +235,31 @@ mergeBy comp xs ys = trace (unlines ["xs="++show xs,"ys="++show ys,"mergeData="+ | |||
233 | -} | 235 | -} |
234 | 236 | ||
235 | 237 | ||
238 | -- | The nth unnamed argument. | ||
236 | param :: Int -> Args String | 239 | param :: Int -> Args String |
237 | param n = Args (Prim (\_ us -> us!!n) (singleton $ exactly (n+1))) [] | 240 | param n = Args (Prim (\_ us -> us!!n) (singleton $ exactly (n+1))) [] |
238 | 241 | ||
242 | -- | All unnamed arguments as a list. | ||
243 | params :: Args [String] | ||
244 | params = Args (Prim (\_ args -> args) (exactly 0 ... PositiveInfinity)) [] | ||
245 | |||
246 | |||
247 | -- | The value of named by the given option name. | ||
239 | arg :: String -> Args String | 248 | arg :: String -> Args String |
240 | arg optname = Args (Prim (\opts _ -> concat $ take 1 $ concat $ take 1 opts) | 249 | arg optname = Args (Prim (\opts _ -> concat $ take 1 $ concat $ take 1 opts) |
241 | (singleton $ exactly 0)) | 250 | (singleton $ exactly 0)) |
242 | [optname] | 251 | [optname] |
243 | 252 | ||
244 | params :: Args [String] | 253 | -- | All values named by the given option name. |
245 | params = Args (Prim (\_ args -> args) (exactly 0 ... PositiveInfinity)) [] | 254 | args :: String -> Args [String] |
255 | args optname = fromMaybe [] <$> optional | ||
256 | (Args (Prim (\opts _ -> concat $ take 1 opts) | ||
257 | (singleton $ exactly 0)) -- no unnamed arguments | ||
258 | [optname]) -- one named argument | ||
246 | 259 | ||
260 | -- | True if the given named option is present. | ||
261 | flag :: String -> Args Bool | ||
262 | flag optname = maybe False (const True) <$> optional (arg optname) | ||
247 | 263 | ||
248 | label :: String -> Args a -> Args a | 264 | label :: String -> Args a -> Args a |
249 | label _ = id | 265 | label _ = id |
@@ -286,7 +302,7 @@ vanilla flags = ArgsStyle { parseInvocation = parse flags } | |||
286 | -- | 302 | -- |
287 | -- * default polyvariadic - Implicit polyvariadic option if no other option is specified. | 303 | -- * default polyvariadic - Implicit polyvariadic option if no other option is specified. |
288 | -- | 304 | -- |
289 | fancy :: [([Char], Int)] -> [[Char]] -> [Char] -> ArgsStyle | 305 | fancy :: [(String, Int)] -> [String] -> String -> ArgsStyle |
290 | fancy sargspsec polyVariadicArgs defaultPoly = ArgsStyle | 306 | fancy sargspsec polyVariadicArgs defaultPoly = ArgsStyle |
291 | { parseInvocation = parse sargspsec polyVariadicArgs defaultPoly } | 307 | { parseInvocation = parse sargspsec polyVariadicArgs defaultPoly } |
292 | where | 308 | where |
@@ -470,8 +486,8 @@ runArgs (os,us) c | |||
470 | where | 486 | where |
471 | os' = sortOn fst os | 487 | os' = sortOn fst os |
472 | dups = mapMaybe notSingle $ groupBy ((==) `on` fst) (os' :: [(String,[String])]) | 488 | dups = mapMaybe notSingle $ groupBy ((==) `on` fst) (os' :: [(String,[String])]) |
473 | where notSingle [x] = Nothing | 489 | where notSingle [x] = Nothing |
474 | notSingle ((k,v):xs) = Just (k,v : map snd xs) | 490 | notSingle ((k,v):xs) = Just (k,v : map snd xs) |
475 | getbit = Map.fromList $ zip (accepts c) [0..] | 491 | getbit = Map.fromList $ zip (accepts c) [0..] |
476 | goods :: [(Int,[String])] | 492 | goods :: [(Int,[String])] |
477 | (bads,goods) = partitionEithers $ map f os' | 493 | (bads,goods) = partitionEithers $ map f os' |