Use new betterhelp.

This commit is contained in:
voussoir 2022-02-12 19:57:25 -08:00
parent 96916c328c
commit 31645f5ce5
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
7 changed files with 108 additions and 44 deletions

View file

@ -1,11 +1,28 @@
<snippet> <snippet>
<content><![CDATA[ <content><![CDATA[
p_$1 = subparsers.add_parser('$1') p_$1 = subparsers.add_parser(
p_$1.add_argument('required_positional') '$1',
p_$1.add_argument('optional_positional', nargs='?', default=None) description='''
p_$1.add_argument('--kwarg', default=None) ''',
p_$1.add_argument('--boolkwarg', action='store_true') )
p_$1.set_defaults(func=$1_argparse) p_$1.add_argument(
'required_positional',
help='''
''',
)
p_$1.add_argument(
'--kwarg',
default=None,
help='''
''',
)
p_$1.add_argument(
'--boolkwarg',
action='store_true',
help='''
''',
)
p_$1.set_defaults(func=$2_argparse)
]]></content> ]]></content>
<tabTrigger>subparser</tabTrigger> <tabTrigger>subparser</tabTrigger>
<scope>source.python</scope> <scope>source.python</scope>

View file

@ -5,7 +5,7 @@ from voussoirkit import betterhelp
# replace the following lines: # replace the following lines:
# args = parser.parse_args(argv) # args = parser.parse_args(argv)
# return args.func(args) # return args.func(args)
return betterhelp.single_main(argv, parser, __doc__) return betterhelp.go(parser, argv)
]]></content> ]]></content>
<tabTrigger>betterhelp</tabTrigger> <tabTrigger>betterhelp</tabTrigger>
<scope>source.python</scope> <scope>source.python</scope>

View file

@ -1,24 +1,5 @@
<snippet> <snippet>
<content><![CDATA[ <content><![CDATA[
'''
$1
======
{$2}
TO SEE DETAILS ON EACH COMMAND, RUN
> $1.py <command> --help
'''
SUB_DOCSTRINGS = dict(
$2='''
$2:
Command description.
'''.strip(),
)
__doc__ = betterhelp.add_previews(__doc__, SUB_DOCSTRINGS)
import argparse import argparse
import sys import sys
@ -32,17 +13,38 @@ def $2_argparse(args):
@vlogging.main_decorator @vlogging.main_decorator
def main(argv): def main(argv):
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(
description='''
''',
)
subparsers = parser.add_subparsers() subparsers = parser.add_subparsers()
p_$2 = subparsers.add_parser('$2') p_$2 = subparsers.add_parser(
p_$2.add_argument('required_positional') '$2',
p_$2.add_argument('optional_positional', nargs='?', default=None) description='''
p_$2.add_argument('--kwarg', default=None) ''',
p_$2.add_argument('--boolkwarg', action='store_true') )
p_$2.add_argument(
'required_positional',
help='''
''',
)
p_$2.add_argument(
'--kwarg',
default=None,
help='''
''',
)
p_$2.add_argument(
'--boolkwarg',
action='store_true',
help='''
''',
)
p_$2.set_defaults(func=$2_argparse) p_$2.set_defaults(func=$2_argparse)
return betterhelp.subparser_main(argv, parser, __doc__, SUB_DOCSTRINGS) return betterhelp.go(parser, argv)
if __name__ == '__main__': if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:])) raise SystemExit(main(sys.argv[1:]))

View file

@ -1,9 +1,5 @@
<snippet> <snippet>
<content><![CDATA[ <content><![CDATA[
'''
$1
======
'''
import argparse import argparse
import sys import sys
@ -17,15 +13,30 @@ def $1_argparse(args):
@vlogging.main_decorator @vlogging.main_decorator
def main(argv): def main(argv):
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(
description='''
parser.add_argument('required_positional') ''',
parser.add_argument('optional_positional', nargs='?', default=None) )
parser.add_argument('--kwarg', default=None) parser.add_argument(
parser.add_argument('--boolkwarg', action='store_true') 'required_positional',
help='''
''',
)
parser.add_argument(
'--kwarg',
default=None,
help='''
''',
)
parser.add_argument(
'--boolkwarg',
action='store_true',
help='''
''',
)
parser.set_defaults(func=$1_argparse) parser.set_defaults(func=$1_argparse)
return betterhelp.single_main(argv, parser, __doc__) return betterhelp.go(parser, argv)
if __name__ == '__main__': if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:])) raise SystemExit(main(sys.argv[1:]))

View file

@ -0,0 +1,13 @@
<snippet>
<content><![CDATA[
parser.add_argument(
'--$1',
action='store_true',
help='''
$2
''',
)
]]></content>
<tabTrigger>flarg</tabTrigger>
<description>argparse store_true argument</description>
</snippet>

View file

@ -0,0 +1,9 @@
<snippet>
<content><![CDATA[
help='''
$1
''',
]]></content>
<tabTrigger>hp</tabTrigger>
<description>hp='''...'''</description>
</snippet>

View file

@ -0,0 +1,12 @@
<snippet>
<content><![CDATA[
parser.add_argument(
'$1',
help='''
$2
''',
)
]]></content>
<tabTrigger>parg</tabTrigger>
<description>argparse argument</description>
</snippet>