Skip to content

Commit 7e2ce6a

Browse files
committed
Add Class CLIParser
1 parent 40e5a57 commit 7e2ce6a

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

hdltools/cli_parser.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#
2+
# Copyright (C) 2025 HDLtools Project
3+
#
4+
# SPDX-License-Identifier: GPL-3.0-or-later
5+
#
6+
7+
"""This file implements the command-line parser."""
8+
9+
import argparse
10+
11+
12+
class CLIParser:
13+
"""Command-line parser."""
14+
15+
def __init__(self, app):
16+
self.parser = argparse.ArgumentParser()
17+
self._add_arguments(app)
18+
19+
def _add_arguments(self, app):
20+
"""Define the arguments based on the application type."""
21+
if app == 'comp':
22+
self.parser.add_argument('--top1')
23+
self.parser.add_argument('--top2')
24+
self.parser.add_argument('files', nargs=2)
25+
else:
26+
self.parser.add_argument('--top')
27+
self.parser.add_argument('--suffix', default=f'_{app}')
28+
self.parser.add_argument('--output')
29+
self.parser.add_argument('file')
30+
31+
def parse(self):
32+
"""Parse the command-line arguments and return them."""
33+
return self.parser.parse_args()

0 commit comments

Comments
 (0)