blob: 1be90e69d2701f3a9f9244b857a6baa849538ea0 [file] [log] [blame]
Thomas Vachuskacdac6e82016-02-29 19:21:49 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Thomas Vachuskacdac6e82016-02-29 19:21:49 -08003 *
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 */
16package org.onosproject.cli.net;
17
18import org.apache.karaf.shell.commands.Command;
19import org.onosproject.cli.AbstractShellCommand;
20import org.onosproject.net.intent.IntentExtensionService;
21
22import java.util.OptionalInt;
23
24/**
25 * Lists the inventory of intents and their states.
26 */
27@Command(scope = "onos", name = "intent-compilers",
28 description = "Lists the mapping from intent type to compiler component")
29public class IntentListCompilers extends AbstractShellCommand {
30
31 @Override
32 protected void execute() {
33 IntentExtensionService service = get(IntentExtensionService.class);
34 OptionalInt length = service.getCompilers().keySet().stream()
35 .mapToInt(s -> s.getName().length())
36 .max();
37 if (length.isPresent()) {
38 service.getCompilers().entrySet().forEach(e -> {
39 print("%-" + length.getAsInt() + "s\t%s",
40 e.getKey().getName(),
41 e.getValue().getClass().getName());
42 });
43 } else {
44 print("There are no compilers registered.");
45 }
46
47 }
48}