mirror of
https://github.com/esphome/esphome.git
synced 2024-12-24 16:58:07 +01:00
Compat argv parsing improvements (#1952)
This commit is contained in:
parent
d0859a7d33
commit
2cb3015a28
@ -514,14 +514,26 @@ def parse_args(argv):
|
|||||||
|
|
||||||
compat_parser.error = _raise
|
compat_parser.error = _raise
|
||||||
|
|
||||||
try:
|
deprecated_argv_suggestion = None
|
||||||
result, unparsed = compat_parser.parse_known_args(argv[1:])
|
|
||||||
last_option = len(argv) - len(unparsed) - 1 - len(result.configuration)
|
if ["dashboard", "config"] == argv[1:3]:
|
||||||
argv = argv[0:last_option] + [result.command] + result.configuration + unparsed
|
# this is most likely meant in new-style arg format. do not try compat parsing
|
||||||
deprecated_argv_suggestion = argv
|
pass
|
||||||
except argparse.ArgumentError:
|
else:
|
||||||
# This is not an old-style command line, so we don't have to do anything.
|
try:
|
||||||
deprecated_argv_suggestion = None
|
result, unparsed = compat_parser.parse_known_args(argv[1:])
|
||||||
|
last_option = len(argv) - len(unparsed) - 1 - len(result.configuration)
|
||||||
|
unparsed = [
|
||||||
|
"--device" if arg in ("--upload-port", "--serial-port") else arg
|
||||||
|
for arg in unparsed
|
||||||
|
]
|
||||||
|
argv = (
|
||||||
|
argv[0:last_option] + [result.command] + result.configuration + unparsed
|
||||||
|
)
|
||||||
|
deprecated_argv_suggestion = argv
|
||||||
|
except argparse.ArgumentError:
|
||||||
|
# This is not an old-style command line, so we don't have to do anything.
|
||||||
|
pass
|
||||||
|
|
||||||
# And continue on with regular parsing
|
# And continue on with regular parsing
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
|
Loading…
Reference in New Issue
Block a user