2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.auth.clieditor.tosca;
23 import org.apache.commons.cli.CommandLine;
24 import org.apache.commons.cli.Option;
25 import org.onap.policy.apex.auth.clieditor.CommandLineParameterParser;
28 * This class reads and handles command line parameters to the Apex CLI Tosca editor.
30 * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
32 public class ApexCliToscaParameterParser extends CommandLineParameterParser {
35 * Construct the options for the CLI editor.
37 public ApexCliToscaParameterParser() {
38 getOptions().addOption(Option.builder("ac").longOpt("apex-config-file")
39 .desc("name of the file containing apex configuration details").hasArg()
40 .argName("APEX_CONFIG_FILE").required(false).type(String.class).build());
41 getOptions().addOption(Option.builder("t").longOpt("tosca-template-file")
42 .desc("name of the input file containing tosca template which needs to be updated with policy").hasArg()
43 .argName("TOSCA_TEMPLATE_FILE").required(false).type(String.class).build());
44 getOptions().addOption(Option.builder("ot").longOpt("output-tosca-file")
45 .desc("name of a file that will contain the output model for the editor").hasArg()
46 .argName("OUTPUT_TOSCA_FILE").required(false).type(String.class).build());
50 * Parse the command line options.
52 * @param args The arguments
53 * @return the CLI parameters
56 public ApexCliToscaParameters parse(final String[] args) {
57 CommandLine commandLine = parseDefault(args);
58 final ApexCliToscaParameters parameters = new ApexCliToscaParameters();
59 parseSingleLetterOptions(commandLine, parameters);
60 parseDoubleLetterOptions(commandLine, parameters);
62 if (commandLine.hasOption("ac")) {
63 parameters.setApexConfigFileName(commandLine.getOptionValue("ac"));
65 if (commandLine.hasOption("t")) {
66 parameters.setInputToscaTemplateFileName(commandLine.getOptionValue("t"));
68 if (commandLine.hasOption("ot")) {
69 parameters.setOutputToscaPolicyFileName(commandLine.getOptionValue("ot"));