From 7236e0ff2127234940f3eedb2824d62ebd9e8f17 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 2 Jun 2018 13:04:25 +0530 Subject: [PATCH] Add CLI docs for the hints kitten --- docs/kittens/hints.rst | 7 ++++--- kittens/hints/main.py | 26 ++++++++++++++++---------- kitty/cli.py | 13 ++++++++++--- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/docs/kittens/hints.rst b/docs/kittens/hints.rst index 4ad7972d0..cbf2578b7 100644 --- a/docs/kittens/hints.rst +++ b/docs/kittens/hints.rst @@ -19,8 +19,9 @@ terminal, very useful for picking files from the output of a ``git`` or ``ls`` c adding them to the command line for the next command. The hints kitten is very powerful to see more detailed help on its various -options and modes of operation, use:: - - kitty +kitten hints --help +options and modes of operation, see below. +Command Line Interface +------------------------- +.. include:: ../generated/cli-kitten-hints.rst diff --git a/kittens/hints/main.py b/kittens/hints/main.py index 134b02a5e..752de87fc 100644 --- a/kittens/hints/main.py +++ b/kittens/hints/main.py @@ -6,7 +6,7 @@ import os import re import string import sys -from functools import lru_cache, partial +from functools import lru_cache from gettext import gettext as _ from itertools import repeat @@ -303,12 +303,12 @@ def run(args, text): # CLI {{{ -OPTIONS = partial(r''' +OPTIONS = r''' --program default=default What program to use to open matched text. Defaults to the default open program -for the operating system. Use a value of - to paste the match into the -terminal window instead. A value of @ will copy the match to the clipboard. +for the operating system. Use a value of :file:`-` to paste the match into the +terminal window instead. A value of :file:`@` will copy the match to the clipboard. --type @@ -319,9 +319,10 @@ The type of text to search for. --regex default=(?m)^\s*(.+)\s*$ -The regular expression to use when --type=regex. If you specify a group in the -regular expression only the group will be matched. This allow you to match text -ignoring a prefix/suffix, as needed. The default expression matches lines. +The regular expression to use when :option:`kitty +kitten hints --type`=regex. +If you specify a group in the regular expression only the group +will be matched. This allow you to match text ignoring a prefix/suffix, as +needed. The default expression matches lines. --url-prefixes @@ -339,12 +340,13 @@ Defaults to the select_by_word_characters setting from kitty.conf. default=3 type=int The minimum number of characters to consider a match. -'''.format, ','.join(sorted(URL_PREFIXES))) +'''.format(','.join(sorted(URL_PREFIXES))).format +help_text = 'Select text from the screen using the keyboard. Defaults to searching for URLs.' +usage = '' def parse_hints_args(args): - msg = 'Select text from the screen using the keyboard. Defaults to searching for URLs.' - return parse_args(args, OPTIONS, '', msg, 'hints') + return parse_args(args, OPTIONS, usage, help_text, 'kitty +kitten hints') def main(args): @@ -395,4 +397,8 @@ if __name__ == '__main__': ans = main(sys.argv) if ans: print(ans) +elif __name__ == '__doc__': + sys.cli_docs['usage'] = usage + sys.cli_docs['options'] = OPTIONS + sys.cli_docs['help_text'] = help_text # }}} diff --git a/kitty/cli.py b/kitty/cli.py index f4d191e2c..e7246d5de 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -189,10 +189,17 @@ def title(x): def option(x): + idx = x.find('-') + if idx > -1: + x = x[idx:] parts = map(bold, x.split()) return ' '.join(parts) +def code(x): + return x + + def env(x): return italic(x) @@ -267,7 +274,7 @@ def prettify(text): def prettify_rst(text): - return text + return re.sub(r':([a-z]+):`([^`]+)`(=[^\s.]+)', r':\1:`\2`:code:`\3`', text) def version(add_rev=False): @@ -419,9 +426,9 @@ def seq_as_rst(seq, usage, message, appname, heading_char='-'): a('') a(textwrap.indent(prettify_rst(t), ' ' * 4)) if defval is not None: - a(textwrap.indent('Default: {}'.format(defval), ' ' * 4)) + a(textwrap.indent('Default: :code:`{}`'.format(defval), ' ' * 4)) if 'choices' in opt: - a(textwrap.indent('Choices: {}'.format(', '.join(opt['choices'])), ' ' * 4)) + a(textwrap.indent('Choices: :code:`{}`'.format(', '.join(opt['choices'])), ' ' * 4)) a('') text = '\n'.join(blocks)