Skip to content

Commit

Permalink
ui/tools/view_glossary.py: switch to argparse, add --no-res flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Dec 19, 2024
1 parent 7010bb5 commit 7990534
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions pyglossary/ui/tools/view_glossary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# mypy: ignore-errors
from __future__ import annotations

import argparse
import os.path
import shlex
import sys
Expand Down Expand Up @@ -59,6 +60,7 @@ def viewGlossary(
filename: str,
formatName: str | None = None,
glos: GlossaryType | None = None,
noRes: bool = False,
) -> None:
highlightEntry = getEntryHighlighter()

Expand All @@ -81,6 +83,8 @@ def viewGlossary(

def handleEntry(entry: EntryType) -> None:
nonlocal index
if noRes and entry.isData():
return
if highlightEntry:
highlightEntry(entry)
entryStr = (
Expand Down Expand Up @@ -110,12 +114,37 @@ def handleEntry(entry: EntryType) -> None:


def main() -> None:
filename = sys.argv[1]
formatName = None
if len(sys.argv) > 2:
formatName = sys.argv[2]
filename = os.path.expanduser(filename)
viewGlossary(filename, formatName=formatName)
parser = argparse.ArgumentParser(
prog=sys.argv[0],
add_help=True,
# allow_abbrev=False,
)
parser.add_argument(
"--format",
dest="formatName",
default=None,
help="format name",
)
parser.add_argument(
"--no-res",
dest="noRes",
action="store_true",
default=False,
help="do not automatically show resources / files",
)
parser.add_argument(
"filename",
action="store",
default="",
nargs=1,
)
args = parser.parse_args()

viewGlossary(
os.path.expanduser(args.filename[0]),
formatName=args.formatName,
noRes=args.noRes,
)


if __name__ == "__main__":
Expand Down

0 comments on commit 7990534

Please sign in to comment.