1 .. This work is licensed under a Creative Commons Attribution 4.0 International License.
2 .. http://creativecommons.org/licenses/by/4.0
3 .. Copyright 2017 Huawei Technologies Co., Ltd.
5 .. _cli_developer_guide:
10 OCLI provides following approaches for developing CLI:
14 The plug-in approach is useful for implementing commands for products that do not support REST APIs.
15 It uses this approach to provide the commands for its platform-related operations and provides the following commands as plug-ins:
17 * Schema-validate : To validate the OCS YAML
18 * Schema-refresh: To enable the newly added commands
20 It also offers the flexibility to implement any kind of command. For example, a specific plug-in command is provided in the CLI to handle
21 HTTP commands, which helps to develop commands by **No coding, just by texting**
23 Follow the steps below to implement new plug-in commands for ONAP:
25 #. Create a new mvn module (ex: demo) under plugins project.
27 #. Use the plugins/sample project as a reference and update the new module demo project pom.xml file.
29 #. Add new command YAML with a unique name under 'src/main/resources/open-cli-schema'.
31 #. To implement a command as a plug-in, create a new plug-in class as follows: ::
33 package org.onap.cli.sample;
37 import org.onap.cli.fw.OnapCommand;
38 import org.onap.cli.fw.OnapCommandSchema;
39 import org.onap.cli.fw.error.OnapCommandException;
40 import org.onap.cli.fw.input.OnapCommandParameter;
45 @OnapCommandSchema(name = "hello-world", version = "sample-1.0", schema = "hello-world.yaml")
46 public class OnapHelloWorldCommand extends OnapCommand {
49 protected void run() throws OnapCommandException {
50 //Read the input arguments
51 Map<String, OnapCommandParameter> paramMap = getParametersMap();
52 OnapCommandParameter nameP = paramMap.get("name");
53 String name = String.valueOf(nameP.getValue());
56 String output = "Hello " + name;
59 this.getResult().getRecordsMap().get("output").getValues().add(output);
63 Note the following points:
65 * 'org.onap.cli.sample.OnapHelloWorldCommand' extends 'OnapCommand' and is annotated with OnapCommandSchema, which carries the command name, product version and schema file name, and is placed under the 'src/main/resources/onap-cli-schema' folder.
67 * getParametersMap() helps to get the arguments value given for a command before executing it
69 * getResult().getRecordsMap() helps to set the attributes values of command after executing it
71 #. Add the new plug-in class package path into the 'src/main/resources/META-INF/services/org.onap.cli.fw.OnapCommand' file
73 #. Now the command is ready. Build the project by running 'mvn clean install'. OCLIP framework automatically delivers these commands as part of the OCLIP zip file as part of this build.
75 #. To test this command, run the command 'oclip hello-world --name amsterdam'
80 All OCLIP commands can be implemented as YAML using HTTP profile.
82 Follow the steps below to implement new commands for ONAP using YAML:
84 #. Install the latest OCLIP using the guide :ref:`cli_installation_guide`.
86 #. Under the open-cli-schema folder, add a new YAML file by referring to :ref:`open_cli_schema_version_1_0`.
88 #. Use the command 'oclip schema-validate' to validate the YAML before testing its functionality.
90 #. Run 'oclip schema-refresh' command to take the new YAML file. We recommended validating the YAML before running this command.
92 #. To test this command, run the command 'oclip CMD-NAME --help'.
97 Find more details about YAML specification at :ref:`open_cli_schema_version_1_0`.
99 Sample hello-world YAML ::
101 open_cli_schema_version: 1.0
103 name: hello-world-http
105 description: First cmd hello world using http running under lighttpd in cli at http://<cli-ip>:8080/version.json
111 description: name of the person
114 default_value: ${DEMO_NAME}
122 description: hello world output
142 output: Hello ${name}, You are running on $b{$.name} $b{$.version}