Skip to content

Commit e84b0c0

Browse files
committed
feat(args): add argument data completion. Add tests to prevent regressions
1 parent 24ee2e9 commit e84b0c0

File tree

8 files changed

+330
-257
lines changed

8 files changed

+330
-257
lines changed

ardupilot_methodic_configurator/annotate_params.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from xml.etree import ElementTree as ET # no parsing, just data-structure manipulation
3838

3939
import argcomplete
40+
from argcomplete.completers import FilesCompleter
4041
from defusedxml import ElementTree as DET # noqa: N814, just parsing, no data-structure manipulation
4142

4243
# URL of the XML file
@@ -61,7 +62,7 @@ def create_argument_parser() -> argparse.ArgumentParser:
6162
parser.add_argument(
6263
"target",
6364
help="The target file or directory.",
64-
)
65+
).completer = FilesCompleter(allowednames=(".param", ".parm"))
6566
parser.add_argument(
6667
"-d",
6768
"--delete-documentation-annotations",
@@ -80,21 +81,31 @@ def create_argument_parser() -> argparse.ArgumentParser:
8081
choices=["none", "missionplanner", "mavproxy"],
8182
default="none",
8283
help="Sort the parameters in the file. Default is %(default)s.",
83-
)
84+
).completer = lambda **_: ["none", "missionplanner", "mavproxy"]
8485
parser.add_argument(
8586
"-t",
8687
"--vehicle-type",
8788
choices=["AP_Periph", "AntennaTracker", "ArduCopter", "ArduPlane", "ArduSub", "Blimp", "Heli", "Rover", "SITL"],
8889
default="ArduCopter",
8990
help="The type of the vehicle. Default is %(default)s.",
90-
)
91+
).completer = lambda **_: [
92+
"AP_Periph",
93+
"AntennaTracker",
94+
"ArduCopter",
95+
"ArduPlane",
96+
"ArduSub",
97+
"Blimp",
98+
"Heli",
99+
"Rover",
100+
"SITL",
101+
]
91102
parser.add_argument(
92103
"-m",
93104
"--max-line-length",
94105
type=int,
95106
default=100,
96107
help="Maximum documentation line length. Default is %(default)s.",
97-
)
108+
).choices = range(80, 121)
98109
parser.add_argument(
99110
"--verbose",
100111
action="store_true",

ardupilot_methodic_configurator/backend_filesystem.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from typing import Any, Optional
2727
from zipfile import ZipFile
2828

29+
from argcomplete.completers import DirectoriesCompleter
30+
2931
from ardupilot_methodic_configurator import _
3032
from ardupilot_methodic_configurator.annotate_params import (
3133
PARAM_DEFINITION_XML_FILE,
@@ -669,15 +671,15 @@ def add_argparse_arguments(parser: ArgumentParser) -> ArgumentParser:
669671
choices=VehicleComponents.supported_vehicles(),
670672
default="",
671673
help=_("The type of the vehicle. Default is ArduCopter"),
672-
)
674+
).choices = lambda **_: VehicleComponents.supported_vehicles()
673675
parser.add_argument(
674676
"--vehicle-dir",
675677
type=str,
676678
default=os_getcwd(),
677679
help=_(
678680
"Directory containing vehicle-specific intermediate parameter files. Default is the current working directory"
679681
),
680-
)
682+
).completer = DirectoriesCompleter()
681683
parser.add_argument(
682684
"--n",
683685
type=int,

ardupilot_methodic_configurator/backend_flightcontroller.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def add_argparse_arguments(parser: ArgumentParser) -> ArgumentParser:
583583
'If set to "none" no connection is made.'
584584
" Default is autodetection"
585585
),
586-
)
586+
).completer = lambda **_: FlightController.__list_serial_ports()
587587
parser.add_argument(
588588
"-r",
589589
"--reboot-time",
@@ -593,5 +593,5 @@ def add_argparse_arguments(parser: ArgumentParser) -> ArgumentParser:
593593
action=CheckRange,
594594
default=7,
595595
help=_("Flight controller reboot time. Default is %(default)s"),
596-
)
596+
).choices = range(5, 51)
597597
return parser

0 commit comments

Comments
 (0)