/
opaDocParameters.opa
163 lines (146 loc) · 4.57 KB
/
opaDocParameters.opa
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* {1 Parameters for the generation}
*
* This module defines the parameters used for interacting with the generation
* of the documentation, as well as a corresponding command line parser.
**/
/**
* {2 Parameters definition}
**/
/**
* Parameters for the generation.
*
* [private]
* Enable the printing of internal abstract implementation of abstract types,
* and printing of private functions and types definition.
* This is used internally for developpement only, the default behavior
* for building the html documentation is to hide these informations.
*
* Currently, there is no more parameters of generation.
**/
type OpaDocParameters.t = {
files : list(string)
help : bool
output_dir : option(string)
private : bool
long_uris : bool
}
/**
* {2 Parameters parsing}
**/
OpaDocParameters = {{
/**
* The default parameters
**/
@private default : OpaDocParameters.t = {
files = []
help = false
output_dir = {none}
private = false
long_uris = true
}
/**
* A distinct family for the '--help' option
*/
@private help_family : CommandLine.family(bool) = {
title = "Help"
init = false
anonymous = []
parsers = [
{ CommandLine.default_parser with
names = [ "--help", "-h"]
description = "Help message on the usage of opadoc"
on_encounter(_) = {no_params = true}
},
]
}
/**
* The commandLine family to use to parse command line options and
* to build the parameters.
**/
@private parameters_family : CommandLine.family(OpaDocParameters.t) = {
title = "Parameters"
init = default
anonymous = []
parsers = [
{ CommandLine.default_parser with
names = [ "--private" ]
description = "Show private and abstract types/values"
on_encounter(state) =
state = { state with private = true }
{no_params = state}
},
{ CommandLine.default_parser with
names = ["--output-dir", "-o"]
description = "Output directory of generated HTML files"
param_doc = "<dir>"
on_param(state) = parser path=(.*) ->
state = { state with output_dir = {some = Text.to_string(path)}}
{no_params = state}
},
{ CommandLine.default_parser with
names = [ "--long-uris" ]
description = "Use long uris of the form stdlib.core.rpc.core.network.opa instead of network.opa"
on_encounter(state) =
state = { state with long_uris = true }
{no_params = state}
},
]
}
/**
* Another distinct family for anonymous arguments
*/
@private anonymous_family : CommandLine.family(list(string)) = {
title = "Anonymous"
init = []
anonymous = [
{
filter = "dirs, *.opa" ;
description = "Give directories and/or some opa files" ;
parse(files) =
parser result={Rule.consume} -> result +> files
},
]
parsers = []
}
/**
* For the simplicity of design, better than passing arround the parameters,
* parameters are available as a global server side reference.
* opadoc is a server side non concurrent application, this is really not
* a problem.
**/
/**
* Internal reference
**/
@private parameters = ServerReference.create(default)
/**
* Parse the command line, and store the parameters into the local reference.
* Parameters are then available via the [OpaDocParameters.get] function
**/
filter_command_line() =
params = CommandLine.filter(parameters_family)
help = CommandLine.filter(help_family)
files = CommandLine.filter(anonymous_family)
params = {params with ~help ~files}
ServerReference.set(parameters, params)
/**
* get the state of paramaters.
* This function should be called once the command line has been parsed
* with [OpaDocParameters.filter_command_line], if not, this returns
* the default parameters.
**/
get() = ServerReference.get(parameters)
}}