d5c66858faae557357ed9fe00d254a91153c1c4b
[policy/apex-pdp.git] /
1 /*-
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
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.CommandLine;
24 import org.apache.commons.cli.Option;
25 import org.onap.policy.apex.auth.clieditor.CommandLineParameterParser;
26
27 /**
28  * This class reads and handles command line parameters to the Apex CLI Tosca editor.
29  *
30  * @author Ajith Sreekumar (ajith.sreekumar@est.tech)
31  */
32 public class ApexCliToscaParameterParser extends CommandLineParameterParser {
33
34     /**
35      * Construct the options for the CLI editor.
36      */
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());
47     }
48
49     /**
50      * Parse the command line options.
51      *
52      * @param args The arguments
53      * @return the CLI parameters
54      */
55     @Override
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);
61
62         if (commandLine.hasOption("ac")) {
63             parameters.setApexConfigFileName(commandLine.getOptionValue("ac"));
64         }
65         if (commandLine.hasOption("t")) {
66             parameters.setInputToscaTemplateFileName(commandLine.getOptionValue("t"));
67         }
68         if (commandLine.hasOption("ot")) {
69             parameters.setOutputToscaPolicyFileName(commandLine.getOptionValue("ot"));
70         }
71         return parameters;
72     }
73
74 }