1 /* Copyright 2016-present Samsung Electronics Co., Ltd. and other contributors
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 function Option(arg, value, default_value, help) {
19 this.default_value = default_value;
25 Option.prototype.printHelp = function() {
26 console.log("\t" + this.arg + "=[" + this.value + "](default: " +
27 this.default_value + ") : " + this.help);
30 function OptionParser() {
35 OptionParser.prototype.addOption = function(arg, value, default_value, help) {
36 var option = new Option(arg, value, default_value, help);
37 this.options.push(option);
40 OptionParser.prototype.parse = function() {
43 for (var idx in this.options) {
44 var option = this.options[idx];
45 var default_value = option.default_value;
46 if (default_value !== "") {
47 options[option.arg] = default_value;
51 for (var aIdx = 2; aIdx < process.argv.length; aIdx++) {
52 var option = process.argv[aIdx];
53 var arg_val = option.split("=");
55 if (arg_val.length != 2 || !arg_val[0] || !arg_val[1]) {
63 for (var oIdx in this.options) {
64 if (arg == this.options[oIdx].arg) {
78 OptionParser.prototype.printHelp = function() {
79 console.log(process.argv[1]);
80 console.log("\noptional arguments");
81 for (var idx in this.options) {
82 this.options[idx].printHelp();
89 module.exports.OptionParser = OptionParser;