diff --git a/README.md b/README.md index b1b2e1ed5..fc5a9f2ee 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,10 @@ Most hardware configurations will work with `-b 230400`, some with `-b 460800`, If you have connectivity problems then you can also set baud rates below 115200. You can also choose 74880, which is the usual baud rate used by the ESP8266 to output [boot log](#boot-log) information. +## Specifying Arguments Via File + +Anywhere on the `esptool.py` command line, you can specify a file name as `@filename.txt` to read one or more arguments from text file `filename.txt`. Arguments can be separated by newlines or spaces, quotes can be used to enclose arguments that span multiple words. Arguments read from the text file are expanded exactly as if they had appeared in that order on the `esptool.py` command line. + ## Commands ### Convert ELF to Binary diff --git a/esptool.py b/esptool.py index 4d8472144..d69bf1657 100755 --- a/esptool.py +++ b/esptool.py @@ -28,6 +28,7 @@ import time import base64 import zlib +import shlex __version__ = "2.0-dev" @@ -1855,6 +1856,8 @@ def add_spi_flash_subparsers(parent): for operation in subparsers.choices.keys(): assert operation in globals(), "%s should be a module function" % operation + expand_file_arguments() + args = parser.parse_args() print 'esptool.py v%s' % __version__ @@ -1896,6 +1899,24 @@ def add_spi_flash_subparsers(parent): else: operation_func(args) +def expand_file_arguments(): + """ Any argument starting with "@" gets replaced with all values read from a text file. + Text file arguments can be split by newline or by space. + Values are added "as-is", as if they were specified in this order on the command line. + """ + new_args = [] + expanded = False + for arg in sys.argv: + if arg.startswith("@"): + expanded = True + with open(arg[1:],"r") as f: + for line in f.readlines(): + new_args += shlex.split(line) + else: + new_args.append(arg) + if expanded: + print "esptool.py %s" % (" ".join(new_args[1:])) + sys.argv = new_args class FlashSizeAction(argparse.Action): """ Custom flash size parser class to support backwards compatibility with megabit size arguments.