blob: 9a2bda8c1d6b7574e6c44d750605adc8b6be4ce4 [file] [log] [blame]
tom0eb04ca2014-08-25 14:34:51 -07001package org.onlab.onos.cli;
2
3import org.apache.karaf.shell.console.OsgiCommandSupport;
4import org.osgi.framework.BundleContext;
5import org.osgi.framework.FrameworkUtil;
6
7/**
8 * Base abstraction of Karaf shell commands.
9 */
10public abstract class AbstractShellCommand extends OsgiCommandSupport {
11
12 /**
tom6d2a43e2014-09-08 01:50:20 -070013 * Returns the reference to the implementation of the specified service.
tom0eb04ca2014-08-25 14:34:51 -070014 *
15 * @param serviceClass service class
16 * @param <T> type of service
17 * @return service implementation
18 */
tom6d2a43e2014-09-08 01:50:20 -070019 public static <T> T get(Class<T> serviceClass) {
tom0eb04ca2014-08-25 14:34:51 -070020 BundleContext bc = FrameworkUtil.getBundle(AbstractShellCommand.class).getBundleContext();
21 return bc.getService(bc.getServiceReference(serviceClass));
22 }
23
tom6d2a43e2014-09-08 01:50:20 -070024 /**
25 * Prints the arguments using the specified format.
26 *
27 * @param format format string; see {@link String#format}
28 * @param args arguments
29 */
30 public static void print(String format, Object... args) {
31 System.out.println(String.format(format, args));
32 }
33
tom0eb04ca2014-08-25 14:34:51 -070034}