Document CLI of panel kitten

This commit is contained in:
Kovid Goyal 2018-06-02 12:24:21 +05:30
parent f857b1afd3
commit 9a615efa83
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
4 changed files with 48 additions and 4 deletions

View File

@ -284,6 +284,16 @@ def write_cli_docs():
p('kitty @', func.name + '\n' + '-' * 120)
p('.. program::', 'kitty @', func.name)
p('\n\n' + as_rst(*cli_params_for(func)))
from kittens.runner import all_kitten_names, get_kitten_cli_docs
for kitten in all_kitten_names():
data = get_kitten_cli_docs(kitten)
if data:
with open(f'generated/cli-kitten-{kitten}.rst', 'w') as f:
p = partial(print, file=f)
p('.. program::', f'kitty +kitten {kitten}')
p('\n\n' + option_spec_as_rst(
data['options'], message=data['help_text'], usage=data['usage'], appname=f'kitty +kitten {kitten}',
heading_char='^'))
# }}}

View File

@ -35,3 +35,9 @@ This will show ``Hello, world.`` at the top edge of your screen for five
seconds. Here the terminal program we are running is ``sh`` with a script to
print out ``Hello, world!``. You can make the terminal program as complex as
you like, as demonstrated in the screenshot above.
Command Line Interface
-------------------------
.. include:: ../generated/cli-kitten-panel.rst

View File

@ -42,11 +42,12 @@ Syntax: :italic:`name=value`. For example: :option:`kitty +kitten panel -o` font
args = None
help_text = 'Use a command line program to draw a GPU accelerated panel on your X11 desktop'
usage = 'program-to-run'
def parse_panel_args(args):
msg = 'Use a command line program to draw a GPU accelerated panel on your X11 desktop'
return parse_args(args, OPTIONS, 'program-to-run', msg, 'panel')
return parse_args(args, OPTIONS, usage, help_text, 'kitty +kitten panel')
def call_xprop(*cmd, silent=False):
@ -141,3 +142,7 @@ def main(sys_args):
if __name__ == '__main__':
main(sys.argv)
elif __name__ == '__doc__':
sys.cli_docs['usage'] = usage
sys.cli_docs['options'] = OPTIONS
sys.cli_docs['help_text'] = help_text

View File

@ -80,11 +80,34 @@ def deserialize(output):
return json.loads(rest[:int(sz)])
def run_kitten(kitten):
def run_kitten(kitten, run_name='__main__'):
import runpy
kitten = resolved_kitten(kitten)
set_debug(kitten)
runpy.run_module('kittens.{}.main'.format(kitten), run_name='__main__')
runpy.run_module('kittens.{}.main'.format(kitten), run_name=run_name)
def all_kitten_names():
ans = getattr(all_kitten_names, 'ans', None)
if ans is None:
n = []
import glob
base = os.path.dirname(os.path.abspath(__file__))
for x in glob.glob(os.path.join(base, '*', '__init__.py')):
q = os.path.basename(os.path.dirname(x))
if q != 'tui':
n.append(q)
all_kitten_names.ans = ans = frozenset(n)
return ans
def get_kitten_cli_docs(kitten):
sys.cli_docs = {}
run_kitten(kitten, run_name='__doc__')
ans = sys.cli_docs
del sys.cli_docs
if 'help_text' in ans and 'usage' in ans and 'options' in ans:
return ans
def main():