5a35499c725391d1e9f3c9843d0b3c821dded4f7
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019-2021 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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.apex.auth.clieditor.tosca;
22
23 import org.apache.commons.cli.Option;
24 import org.onap.policy.apex.auth.clieditor.CommandLineParameterParser;
25
26 /**
27  * This class reads and handles command line parameters to the Apex CLI Tosca editor.
28  *
29  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
30  */
31 public class ApexCliToscaParameterParser extends CommandLineParameterParser {
32
33     /**
34      * Construct the options for the CLI editor.
35      */
36     public ApexCliToscaParameterParser() {
37         getOptions().addOption(Option.builder("ac").longOpt("apex-config-file")
38             .desc("name of the file containing apex configuration details").hasArg()
39             .argName("APEX_CONFIG_FILE").required(false).type(String.class).build());
40         getOptions().addOption(Option.builder("t").longOpt("tosca-template-file")
41             .desc("name of the input file containing tosca template which needs to be updated with policy").hasArg()
42             .argName("TOSCA_TEMPLATE_FILE").required(false).type(String.class).build());
43         getOptions().addOption(Option.builder("ot").longOpt("output-tosca-file")
44             .desc("name of a file that will contain the output model for the editor").hasArg()
45             .argName("OUTPUT_TOSCA_FILE").required(false).type(String.class).build());
46     }
47
48     /**
49      * Parse the command line options.
50      *
51      * @param args The arguments
52      * @return the CLI parameters
53      */
54     @Override
55     public ApexCliToscaParameters parse(final String[] args) {
56         var commandLine = parseDefault(args);
57         final var parameters = new ApexCliToscaParameters();
58         parseSingleLetterOptions(commandLine, parameters);
59         parseDoubleLetterOptions(commandLine, parameters);
60
61         if (commandLine.hasOption("ac")) {
62             parameters.setApexConfigFileName(commandLine.getOptionValue("ac"));
63         }
64         if (commandLine.hasOption("t")) {
65             parameters.setInputToscaTemplateFileName(commandLine.getOptionValue("t"));
66         }
67         if (commandLine.hasOption("ot")) {
68             parameters.setOutputToscaPolicyFileName(commandLine.getOptionValue("ot"));
69         }
70         return parameters;
71     }
72
73 }