Skip to content

Commit

Permalink
Add 'bikeshed debug --print-metadata', to output all the parsed metad…
Browse files Browse the repository at this point in the history
…ata. Fixes #2214.
  • Loading branch information
tabatkins committed Jan 13, 2022
1 parent 40e293a commit cd66b7b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
17 changes: 17 additions & 0 deletions bikeshed/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ def main():
action="store_true",
help="Clobbers the readonly data files with the mutable ones.",
)
debugCommands.add_argument(
"--print-metadata",
dest="printMetadata",
action="store_true",
help="Prints all the metadata parsed for the spec as JSON. Top-level keys are presented in increasing order of importance; second-level keys are in order of first appearance in each context.",
)

refParser = subparsers.add_parser("refs", help="Search Bikeshed's ref database.")
refParser.add_argument("infile", nargs="?", default=None, help="Path to the source file.")
Expand Down Expand Up @@ -554,6 +560,17 @@ def handleDebug(options, extras):
constants.quiet = 0
update.updateReadonlyDataFiles()
warn("Don't forget to bump the version number!")
elif options.printMetadata:
doc = Spec(inputFilename=options.infile)
doc.mdCommandLine = metadata.fromCommandLine(extras)
doc.preprocess()
md = {
"defaults.include": doc.mdDefaults.allData,
"computed-metadata.include": doc.mdOverridingDefaults.allData,
"document": doc.mdDocument.allData,
"command-line": doc.mdCommandLine.allData,
}
print(json.dumps(md, indent=2, default=getjson))


def handleRefs(options, extras):
Expand Down
5 changes: 5 additions & 0 deletions bikeshed/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ def displayVshortname(self):
def __init__(self):
self.hasMetadata = False

# All metadata ever passed to .addData()
self.allData = defaultdict(list)

# required metadata
self.abstract = []
self.ED = None
Expand Down Expand Up @@ -139,12 +142,14 @@ def addData(self, key, val, lineNum=None):
val = val.strip()

if key.startswith("!"):
self.allData[key].append(val)
key = key[1:]
self.otherMetadata[key].append(val)
return

if key not in ("ED", "TR", "URL"):
key = key.title()
self.allData[key].append(val)

if key not in knownKeys:
die(f'Unknown metadata key "{key}". Prefix custom keys with "!".', lineNum=lineNum)
Expand Down

0 comments on commit cd66b7b

Please sign in to comment.