Skip to content

Commit beb1f28

Browse files
committed
Detect if you've likely hit the 'spaces in unknown optional args' issue and fail if so.
1 parent 5caa5a7 commit beb1f28

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

bikeshed/Spec.py

+20
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ def __init__(
4747
fileRequester=None,
4848
testing=False,
4949
):
50+
catchArgparseBug(inputFilename)
5051
self.valid = False
5152
self.lineNumbers = lineNumbers
5253
if lineNumbers:
@@ -322,6 +323,7 @@ def fixMissingOutputFilename(self, outputFilename):
322323
return outputFilename
323324

324325
def finish(self, outputFilename=None, newline=None):
326+
catchArgparseBug(outputFilename)
325327
self.printResultMessage()
326328
outputFilename = self.fixMissingOutputFilename(outputFilename)
327329
rendered = self.serialize()
@@ -492,6 +494,24 @@ def findImplicitInputFile():
492494
return None
493495

494496

497+
def catchArgparseBug(string):
498+
# Argparse has had a long-standing bug
499+
# https://bugs.python.org/issue22433
500+
# about spaces in the values of unknown optional arguments
501+
# (even when the space is in a quoted string!).
502+
# I can't fix this without doing a lot of work myself,
503+
# but I *can* discover when it has been tripped,
504+
# as the input or output filename will look like
505+
# a command-line flag, very unlikely on its own.
506+
507+
if isinstance(string, str) and string.startswith("--") and "=" in string:
508+
m.die(
509+
"You're hitting a bug with Python's argparse library. Please specify both the input and output filenames manually, and move all command-line flags with spaces in their values to after those arguments.\nSee <https://tabatkins.github.io/bikeshed/#md-issues> for details."
510+
)
511+
return False
512+
return True
513+
514+
495515
constants.specClass = Spec
496516

497517
styleColors = """

0 commit comments

Comments
 (0)