Skip to content

Commit

Permalink
[builtin/help refactor] Start using Dict metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
Andy C committed Aug 7, 2023
1 parent 3b6d177 commit bfb4ac1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
2 changes: 2 additions & 0 deletions build/py.sh
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,8 @@ all() {
# requires re2c: deps/from-tar.sh layer-re2c
fastlex
time-helper

# help topics and chapter links are extracted from doc/ref
build/doc.sh all-help
}

Expand Down
7 changes: 4 additions & 3 deletions doctools/help_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,15 +478,16 @@ def main(argv):
pages = argv[5:]

topics, debug_info = CardsFromChapters(out_dir, 'h3', pages)
topic_dict = dict((topic_id, '') for topic_id in topics)
with open(py_out, 'w') as f:
f.write('TOPICS = %s\n' % pprint.pformat(topics))
f.write('TOPICS = %s\n' % pprint.pformat(topic_dict))

f.write('''
from typing import List
from typing import Dict
def TopicMetadata():
# type: () -> List[str]
# type: () -> Dict[str, str]
return TOPICS
''')

Expand Down
21 changes: 13 additions & 8 deletions osh/builtin_comp.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
from osh.split import SplitContext
from osh.word_eval import NormalWordEvaluator

HELP_TOPICS = [] # type: List[str]
TOPIC_META = {} # type: Dict[str, str]

if mylib.PYTHON:
try:
from _devbuild.gen import help_meta # type: ignore
HELP_TOPICS = help_meta.TopicMetadata()
TOPIC_META = help_meta.TopicMetadata()
except ImportError:
# This happens in the 'minimal' dev build
pass
Expand Down Expand Up @@ -102,17 +102,20 @@ def __init__(
):
# type: (...) -> None
"""
Args:
cmd_ev: CommandEvaluator for compgen -F
parse_ctx, word_ev, splitter: for compgen -W
"""
Args:
cmd_ev: CommandEvaluator for compgen -F
parse_ctx, word_ev, splitter: for compgen -W
"""
self.cmd_ev = cmd_ev
self.parse_ctx = parse_ctx
self.word_ev = word_ev
self.splitter = splitter
self.comp_lookup = comp_lookup
self.errfmt = errfmt

# lazily initialized
self.help_topics = None # type: List[str]

def Build(self, argv, attrs, base_opts):
# type: (List[str], _Attributes, Dict[str, bool]) -> UserSpec
"""Given flags to complete/compgen, return a UserSpec."""
Expand Down Expand Up @@ -180,8 +183,10 @@ def Build(self, argv, attrs, base_opts):
a = completion.VariablesAction(cmd_ev.mem)

elif name == 'helptopic':
# Note: it would be nice to have 'helpgroup' for help -i too
a = _FixedWordsAction(HELP_TOPICS)
# Lazy initialization
if self.help_topics is None:
self.help_topics = TOPIC_META.keys()
a = _FixedWordsAction(self.help_topics)

elif name == 'setopt':
a = _FixedWordsAction(consts.SET_OPTION_NAMES)
Expand Down

0 comments on commit bfb4ac1

Please sign in to comment.