blob: b72210c98459181d9d13de1bca32ee1bfcc633ae [file] [log] [blame]
Thomas Vachuska4cfcc562015-06-03 09:51:02 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Thomas Vachuska4cfcc562015-06-03 09:51:02 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Thomas Vachuska99b7bbe2018-02-01 15:29:46 -080016package org.onosproject.ui.impl.cli;
Thomas Vachuska4cfcc562015-06-03 09:51:02 -070017
18import com.fasterxml.jackson.databind.JsonNode;
19import com.fasterxml.jackson.databind.ObjectMapper;
20import com.fasterxml.jackson.databind.node.ArrayNode;
Ray Milkeyd84f89b2018-08-17 14:54:17 -070021import org.apache.karaf.shell.api.action.Command;
Thomas Vachuska99b7bbe2018-02-01 15:29:46 -080022import org.onosproject.cli.AbstractShellCommand;
Thomas Vachuska4cfcc562015-06-03 09:51:02 -070023import org.onosproject.ui.UiExtension;
24import org.onosproject.ui.UiExtensionService;
25
26import java.util.List;
27
28/**
Simon Hunt23f9c7b2017-07-10 20:00:30 -070029 * Lists all registered UI views.
Thomas Vachuska4cfcc562015-06-03 09:51:02 -070030 */
31@Command(scope = "onos", name = "ui-views",
Simon Hunt23f9c7b2017-07-10 20:00:30 -070032 description = "Lists all registered UI views")
Thomas Vachuska4cfcc562015-06-03 09:51:02 -070033public class UiViewListCommand extends AbstractShellCommand {
34
35 private static final String FMT = "id=%s, category=%s, label=%s, icon=%s";
36
37 @Override
Ray Milkeyd84f89b2018-08-17 14:54:17 -070038 protected void doExecute() {
Thomas Vachuska4cfcc562015-06-03 09:51:02 -070039 UiExtensionService service = get(UiExtensionService.class);
40 if (outputJson()) {
41 print("%s", json(service.getExtensions()));
42 } else {
43 service.getExtensions().forEach(ext -> ext.views()
Simon Hunt23f9c7b2017-07-10 20:00:30 -070044 .forEach(v -> print(FMT, v.id(), v.category(),
Thomas Vachuska4cfcc562015-06-03 09:51:02 -070045 v.label(), v.iconId())));
46 }
47 }
48
49 private JsonNode json(List<UiExtension> extensions) {
50 ObjectMapper mapper = new ObjectMapper();
51 ArrayNode node = mapper.createArrayNode();
52 extensions.forEach(ext -> ext.views()
53 .forEach(v -> node.add(mapper.createObjectNode()
54 .put("id", v.id())
Simon Hunt23f9c7b2017-07-10 20:00:30 -070055 .put("category", v.category().toString())
Thomas Vachuska4cfcc562015-06-03 09:51:02 -070056 .put("label", v.label())
57 .put("icon", v.iconId()))));
58 return node;
59 }
60
61}