Add CLI bundle to the startup archetype
[controller.git] / opendaylight / archetypes / opendaylight-startup / src / main / resources / archetype-resources / cli / src / main / java / __packageInPathFormat__ / cli / commands / __classPrefix__CliTestCommand.java
1 #set( $symbol_pound = '#' )
2 #set( $symbol_dollar = '$' )
3 #set( $symbol_escape = '\' )
4 /*
5  * Copyright © ${copyrightYear} ${copyright} and others.  All rights reserved.
6  *
7  * This program and the accompanying materials are made available under the
8  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
9  * and is available at http://www.eclipse.org/legal/epl-v10.html
10  */
11 package ${package}.cli.commands;
12
13 import org.apache.karaf.shell.commands.Command;
14 import org.apache.karaf.shell.commands.Option;
15 import org.apache.karaf.shell.console.AbstractAction;
16 import ${package}.cli.api.${classPrefix}CliCommands;
17 import org.slf4j.Logger;
18 import org.slf4j.LoggerFactory;
19
20 /**
21  * This is an example class. The class name can be renamed to match the command implementation that it will invoke.
22  * Specify command details by updating the fields in the Command annotation below.
23  */
24 @Command(name = "test-command", scope = "add the scope of the command, usually project name", description = "add a description for the command")
25 public class ${classPrefix}CliTestCommand extends AbstractAction {
26
27     private static final Logger LOG = LoggerFactory.getLogger(${classPrefix}CliTestCommand.class);
28     protected final ${classPrefix}CliCommands service;
29
30     public ${classPrefix}CliTestCommand(final ${classPrefix}CliCommands service) {
31         this.service = service;
32     }
33
34     /**
35      * Add the arguments required by the command.
36      * Any number of arguments can be added using the Option annotation
37      * The below argument is just an example and should be changed as per your requirements
38      */
39     @Option(name = "-tA",
40             aliases = { "--testArgument" },
41             description = "test command argument",
42             required = true,
43             multiValued = false)
44     private Object testArgument;
45
46     @Override
47     protected Object doExecute() throws Exception {
48         /**
49          * Invoke commannd implementation here using the service instance.
50          * Implement how you want the output of the command to be displayed.
51          * Below is just an example.
52          */
53         final String testMessage = (String) service.testCommand(testArgument);
54         return testMessage;
55     }
56 }