blob: 00b44aa453733e31b8a67b3444023bc6eb27109b [file] [log] [blame]
Thomas Vachuska96d55b12015-05-11 08:52:03 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska96d55b12015-05-11 08:52:03 -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 */
16package org.onosproject.cli.cfg;
17
18import org.apache.karaf.shell.commands.Command;
19import org.apache.karaf.shell.commands.Option;
20import org.onosproject.cli.AbstractShellCommand;
Ray Milkeya4122362015-08-18 15:19:08 -070021import org.onosproject.net.config.ConfigFactory;
22import org.onosproject.net.config.NetworkConfigRegistry;
Thomas Vachuska96d55b12015-05-11 08:52:03 -070023
24/**
25 * Displays network configuration registry contents.
26 */
27@Command(scope = "onos", name = "netcfg-registry",
28 description = "Displays network configuration registry contents")
29public class NetworkConfigRegistryCommand extends AbstractShellCommand {
30
31 private static final String FMT = "subjectKey=%s, configKey=%s, subjectClass=%s, configClass=%s";
32 private static final String SHORT_FMT = "%-12s %-12s %-40s %s";
33
34 @Option(name = "-s", aliases = "--short", description = "Show short output only",
35 required = false, multiValued = false)
36 private boolean shortOnly = false;
37
38 @Override
39 protected void execute() {
40 get(NetworkConfigRegistry.class).getConfigFactories().forEach(this::print);
41 }
42
43 private void print(ConfigFactory configFactory) {
44 print(shortOnly ? SHORT_FMT : FMT,
Thomas Vachuskaea5adc62015-10-07 11:52:30 -070045 configFactory.subjectFactory().subjectClassKey(),
Thomas Vachuska96d55b12015-05-11 08:52:03 -070046 configFactory.configKey(),
47 configFactory.subjectFactory().subjectClass().getName(),
48 configFactory.configClass().getName());
49 }
50
51}