-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathHelp.idr
More file actions
42 lines (37 loc) · 1.19 KB
/
Help.idr
File metadata and controls
42 lines (37 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
module Replica.Command.Help
import Data.List
import Data.List1
import Data.String
import Replica.Command.Info
import Replica.Command.Run
import Replica.Command.Set
import Replica.Command.New
import Replica.Command.Version
import public Replica.Help
import Replica.Option.Types
import Replica.Other.Validation
export
help : Help
help = MkHelp
{ name = "help"
, usage = Just "replica COMMAND [COMMAND_OPTIONS]"
, description = "Integration testing for command line interfaces"
, chapter = [ ("Commands", helpRun ::: [helpTest, helpInfo, helpSet, helpNew, helpVersion])
]
, lastWords = Just "Run 'replica help COMMAND' for more information on a command."
}
parseHelp' : Help -> List1 String -> ParseResult Help
parseHelp' help xs@(name:::ys) =
if name /= help.name
then InvalidOption (pure help) xs
else case ys of
[] => Done help
(next::ys') => let
subs = foldMap (forget . snd) help.chapter
in foldl
(\res, h => res <+> parseHelp' h (assert_smaller xs (next:::ys')))
(InvalidOption (pure help) $ pure "Cannot find help for '\{unwords ys}'")
subs
export
parseHelp : List1 String -> ParseResult Help
parseHelp = parseHelp' help