1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Translate command results to json
18 import commands
::commands_model
19 import commands
::commands_graph
20 import commands
::commands_usage
21 import commands
::commands_catalog
22 import commands
::commands_ini
23 import commands
::commands_main
25 import templates
::templates_json
26 import catalog
::catalog_json
28 redef class DocCommand
29 # Return a JSON Serializable representation of `self` results
30 fun to_json
: nullable Serializable is abstract
35 redef class CmdMessage
36 # Return a JSON Serializable representation of `self`
37 fun to_json
: nullable Serializable do
38 var obj
= new JsonObject
39 obj
["status"] = class_name
46 redef fun to_json
do return mentity
51 var obj
= new JsonObject
52 obj
["results"] = results
61 redef class CmdEntityList
62 redef fun to_json
do return super
67 redef class CmdComment
69 var obj
= new JsonObject
70 var render
= self.render_comment
71 if render
!= null then
72 obj
["documentation"] = render
.write_to_string
78 redef class CmdEntityLink
80 var obj
= new JsonObject
82 if text
!= null then obj
["text"] = text
83 var title
= self.title
84 if title
!= null then obj
["title"] = title
91 var obj
= new JsonObject
94 obj
["location"] = node
.location
96 var output
= render_code
(node
)
97 if output
!= null then
98 obj
["code"] = output
.write_to_string
106 var obj
= new JsonObject
108 if output
!= null then
109 obj
["graph"] = output
.write_to_string
115 redef class CmdMetadata
116 redef fun to_json
do return metadata
121 redef class CmdCatalogStats
122 redef fun to_json
do return stats
125 redef class CmdCatalogTags
126 redef fun to_json
do return packages_count_by_tags
129 redef class CmdCatalogTag
131 var obj
= super.as(JsonObject)
137 redef class CmdCatalogPerson
138 redef fun to_json
do return person
141 redef class CmdCatalogMaintaining
143 var obj
= new JsonObject
144 obj
["person"] = person
145 obj
["results"] = results
154 redef class CmdCatalogContributing
156 var obj
= new JsonObject
157 obj
["person"] = person
158 obj
["results"] = results
169 redef class CmdIniDescription
171 var obj
= new JsonObject
177 redef class CmdIniGitUrl
179 var obj
= new JsonObject
185 redef class CmdIniCloneCommand
187 var obj
= new JsonObject
188 obj
["command"] = command
193 redef class CmdIniIssuesUrl
195 var obj
= new JsonObject
201 redef class CmdIniMaintainer
203 var obj
= new JsonObject
204 obj
["maintainer"] = maintainer
209 redef class CmdIniContributors
211 var obj
= new JsonObject
212 obj
["contributors"] = contributors
217 redef class CmdIniLicense
219 var obj
= new JsonObject
220 obj
["license"] = license
225 redef class CmdLicenseFile
227 var obj
= new JsonObject
233 redef class CmdLicenseFileContent
235 var obj
= super.as(JsonObject)
236 obj
["content"] = content
241 redef class CmdContribFile
243 var obj
= new JsonObject
249 redef class CmdContribFileContent
251 var obj
= super.as(JsonObject)
252 obj
["content"] = content
261 var obj
= new JsonObject
262 obj
["results"] = results
267 redef class CmdMainCompile
269 var obj
= new JsonObject
270 obj
["command"] = command
275 redef class CmdTesting
277 var obj
= new JsonObject
278 obj
["command"] = command
283 redef class CmdManSynopsis
285 var obj
= new JsonObject
286 obj
["synopsis"] = synopsis
291 redef class CmdManOptions
293 var obj
= new JsonObject
294 obj
["options"] = options