|
3 | 3 | # Copyright (c) 2020 LG Electronics Inc. |
4 | 4 | # SPDX-License-Identifier: Apache-2.0 |
5 | 5 |
|
6 | | -import getopt |
7 | 6 | import os |
8 | | -import sys |
9 | 7 | import json |
10 | 8 | from datetime import datetime |
11 | 9 | import logging |
|
16 | 14 | from fosslight_util.output_format import check_output_format, write_output_file |
17 | 15 | from ._help import print_help_msg_convert, print_version |
18 | 16 | from ._license_matched import get_license_list_to_print |
| 17 | +import argparse |
19 | 18 |
|
20 | 19 | logger = logging.getLogger(constant.LOGGER_NAME) |
21 | 20 | _PKG_NAME = "fosslight_source" |
@@ -130,31 +129,34 @@ def get_detected_licenses_from_scancode(scancode_json_file, need_license): |
130 | 129 |
|
131 | 130 |
|
132 | 131 | def main(): |
133 | | - argv = sys.argv[1:] |
134 | 132 | path_to_find_json = os.getcwd() |
135 | 133 | output_file_name = "" |
136 | 134 | print_matched_text = False |
137 | 135 | format = "" |
138 | 136 |
|
139 | | - try: |
140 | | - opts, args = getopt.getopt(argv, 'hvmp:o:f:') |
141 | | - for opt, arg in opts: |
142 | | - if opt == "-h": |
143 | | - print_help_msg_convert() |
144 | | - elif opt == "-v": |
145 | | - print_version(_PKG_NAME) |
146 | | - elif opt == "-p": |
147 | | - path_to_find_json = arg |
148 | | - if not path_to_find_json: |
149 | | - path_to_find_json = os.getcwd() |
150 | | - elif opt == "-o": |
151 | | - output_file_name = arg |
152 | | - elif opt == "-m": |
153 | | - print_matched_text = True |
154 | | - elif opt == "-f": |
155 | | - format = arg |
156 | | - except Exception: |
| 137 | + parser = argparse.ArgumentParser(description='FOSSLight Source Convert', |
| 138 | + prog='fosslight_source_convert', add_help=False) |
| 139 | + parser.add_argument('-h', '--help', action='store_true', required=False) |
| 140 | + parser.add_argument('-v', '--version', action='store_true', required=False) |
| 141 | + parser.add_argument('-p', '--path', nargs=1, type=str, required=False) |
| 142 | + parser.add_argument('-o', '--output', nargs=1, type=str, required=False, default="") |
| 143 | + parser.add_argument('-m', '--matched', action='store_true', required=False) |
| 144 | + parser.add_argument('-f', '--format', nargs=1, type=str, required=False) |
| 145 | + args = parser.parse_args() |
| 146 | + |
| 147 | + if args.help: |
157 | 148 | print_help_msg_convert() |
| 149 | + if args.version: |
| 150 | + print_version(_PKG_NAME) |
| 151 | + if not args.path: |
| 152 | + path_to_find_json = os.getcwd() |
| 153 | + else: |
| 154 | + path_to_find_json = ''.join(args.path) |
| 155 | + output_file_name = ''.join(args.output) |
| 156 | + if args.matched: |
| 157 | + print_matched_text = True |
| 158 | + if args.format: |
| 159 | + format = ''.join(args.format) |
158 | 160 |
|
159 | 161 | if path_to_find_json == "": |
160 | 162 | print_help_msg_convert() |
|
0 commit comments