Skip to content

Commit c6656a1

Browse files
committed
Group help text by parser
1 parent 2aa353a commit c6656a1

File tree

1 file changed

+24
-10
lines changed
  • src/fprime_gds/executables

1 file changed

+24
-10
lines changed

src/fprime_gds/executables/cli.py

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,18 @@ def get_parser(self) -> argparse.ArgumentParser:
9090
add_help=True,
9191
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
9292
)
93-
for flags, keywords in self.get_arguments().items():
94-
parser.add_argument(*flags, **keywords)
93+
if not hasattr(self, "constituents"):
94+
for flags, keywords in self.get_arguments().items():
95+
parser.add_argument(*flags, **keywords)
96+
else:
97+
for constituent in sorted(self.constituents, key=lambda x: x.description):
98+
subparser = parser.add_argument_group(title=constituent.description)
99+
for flags, keywords in constituent.get_arguments().items():
100+
try:
101+
subparser.add_argument(*flags, **keywords)
102+
except argparse.ArgumentError:
103+
# Constituent tree has duplicates -> flag has already been added, pass
104+
pass
95105
return parser
96106

97107
def reproduce_cli_args(self, args_ns):
@@ -252,7 +262,7 @@ def handle_arguments(self, args, **kwargs):
252262
class PluginArgumentParser(ParserBase):
253263
"""Parser for arguments coming from plugins"""
254264

255-
DESCRIPTION = "Parse plugin CLI arguments and selections"
265+
DESCRIPTION = "Plugin options"
256266
FPRIME_CHOICES = {
257267
"framing": "fprime",
258268
"communication": "ip",
@@ -378,7 +388,7 @@ def handle_arguments(self, args, **kwargs):
378388
class CommExtraParser(ParserBase):
379389
"""Parses extra communication arguments"""
380390

381-
DESCRIPTION = "Process arguments needed to specify arguments for communication"
391+
DESCRIPTION = "Communications options"
382392

383393
def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]:
384394
"""Get arguments for the comm-layer parser"""
@@ -406,7 +416,7 @@ class LogDeployParser(ParserBase):
406416
to end up in the proper place.
407417
"""
408418

409-
DESCRIPTION = "Process arguments needed to specify a logging"
419+
DESCRIPTION = "Logging options"
410420

411421
def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]:
412422
"""Return arguments to parse logging options"""
@@ -469,7 +479,7 @@ class MiddleWareParser(ParserBase):
469479
however; it should be close enough.
470480
"""
471481

472-
DESCRIPTION = "Process arguments needed to specify a tool using the middleware"
482+
DESCRIPTION = "Middleware options"
473483

474484
def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]:
475485
"""Return arguments necessary to run a and connect to the GDS middleware"""
@@ -541,6 +551,8 @@ def handle_arguments(self, args, **kwargs):
541551
class DictionaryParser(DetectionParser):
542552
"""Parser for deployments"""
543553

554+
DESCRIPTION = "Dictionary options"
555+
544556
def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]:
545557
"""Arguments to handle deployments"""
546558
return {
@@ -580,6 +592,8 @@ def handle_arguments(self, args, **kwargs):
580592
class FileHandlingParser(ParserBase):
581593
"""Parser for deployments"""
582594

595+
DESCRIPTION = "File handling options"
596+
583597
def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]:
584598
"""Arguments to handle deployments"""
585599

@@ -684,7 +698,7 @@ class GdsParser(ParserBase):
684698
Note: deployment can help in setting both dictionary and logs, but isn't strictly required.
685699
"""
686700

687-
DESCRIPTION = "Process arguments needed to specify a tool using the GDS"
701+
DESCRIPTION = "GUI options"
688702

689703
def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]:
690704
"""Return arguments necessary to run a binary deployment via the GDS"""
@@ -731,7 +745,7 @@ class BinaryDeployment(DetectionParser):
731745
and represents the flight-side of the equation.
732746
"""
733747

734-
DESCRIPTION = "Process arguments needed for running F prime binary"
748+
DESCRIPTION = "FPrime binary options"
735749

736750
def get_arguments(self) -> Dict[Tuple[str, ...], Dict[str, Any]]:
737751
"""Return arguments necessary to run a binary deployment via the GDS"""
@@ -777,7 +791,7 @@ class SearchArgumentsParser(ParserBase):
777791
"""Parser for search arguments"""
778792

779793
DESCRIPTION = (
780-
"Process arguments relevant to searching/filtering Channels/Events/Commands"
794+
"Searching and filtering options"
781795
)
782796

783797
def __init__(self, command_name: str) -> None:
@@ -823,7 +837,7 @@ def handle_arguments(self, args, **kwargs):
823837
class RetrievalArgumentsParser(ParserBase):
824838
"""Parser for retrieval arguments"""
825839

826-
DESCRIPTION = "Process arguments relevant to retrieving Channels/Events"
840+
DESCRIPTION = "Data retrieval options"
827841

828842
def __init__(self, command_name: str) -> None:
829843
self.command_name = command_name

0 commit comments

Comments
 (0)