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
23 import model
::model_json
24 import catalog
::catalog_json
27 redef class DocCommand
28 # Return a JSON Serializable representation of `self` results
29 fun to_json
: nullable Serializable is abstract
34 redef class CmdMessage
35 # Return a JSON Serializable representation of `self`
36 fun to_json
: nullable Serializable do
37 var obj
= new JsonObject
38 obj
["status"] = class_name
45 redef fun to_json
do return mentity
50 var obj
= new JsonObject
51 obj
["results"] = results
60 redef class CmdEntityList
61 redef fun to_json
do return super
66 redef class CmdComment
68 var obj
= new JsonObject
69 var render
= self.render
70 if render
!= null then
71 obj
["documentation"] = render
.write_to_string
79 var obj
= new JsonObject
82 obj
["location"] = node
.location
85 if output
!= null then
86 obj
["code"] = output
.write_to_string
94 var obj
= new JsonObject
96 if output
!= null then
97 obj
["graph"] = output
.write_to_string
103 redef class CmdMetadata
104 redef fun to_json
do return metadata
109 redef class CmdCatalogStats
110 redef fun to_json
do return stats
113 redef class CmdCatalogTags
114 redef fun to_json
do return packages_count_by_tags
117 redef class CmdCatalogTag
119 var obj
= super.as(JsonObject)
125 redef class CmdCatalogPerson
126 redef fun to_json
do return person
129 redef class CmdCatalogMaintaining
131 var obj
= new JsonObject
132 obj
["person"] = person
133 obj
["results"] = results
142 redef class CmdCatalogContributing
144 var obj
= new JsonObject
145 obj
["person"] = person
146 obj
["results"] = results