Improve argparse, betterhelp snippets.

This commit is contained in:
voussoir 2021-01-14 02:30:40 -08:00
parent 6f9ec9a003
commit f482b3dab9
7 changed files with 67 additions and 5 deletions

View file

@ -3,10 +3,16 @@
import argparse import argparse
import sys import sys
from voussoirkit import vlogging
log = vlogging.getLogger(__name__)
def $1_argparse(args): def $1_argparse(args):
return $1() return $1()
def main(argv): def main(argv):
argv = vlogging.set_level_by_argv(log, argv)
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('required_positional') parser.add_argument('required_positional')
@ -26,5 +32,5 @@ if __name__ == '__main__':
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> --> <!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger --> <!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> --> <scope>source.python</scope>
</snippet> </snippet>

View file

@ -3,10 +3,16 @@
import argparse import argparse
import sys import sys
from voussoirkit import vlogging
log = vlogging.getLogger(__name__)
def $1_argparse(args): def $1_argparse(args):
return $1() return $1()
def main(argv): def main(argv):
argv = vlogging.set_level_by_argv(log, argv)
parser = argparse.ArgumentParser(description=__doc__) parser = argparse.ArgumentParser(description=__doc__)
subparsers = parser.add_subparsers() subparsers = parser.add_subparsers()
@ -28,5 +34,5 @@ if __name__ == '__main__':
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> --> <!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger --> <!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> --> <scope>source.python</scope>
</snippet> </snippet>

View file

@ -11,5 +11,5 @@ p_$1.set_defaults(func=$1_argparse)
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> --> <!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger --> <!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> --> <scope>source.python</scope>
</snippet> </snippet>

View file

@ -0,0 +1,32 @@
<snippet>
<content><![CDATA[
from voussoirkit import betterhelp
DOCSTRING = '''
$1
======
{$2}
TO SEE DETAILS ON EACH COMMAND, RUN
> $1.py <command> --help
'''
SUB_DOCSTRINGS = dict(
$2='''
$2:
Command description.
'''.strip(),
)
DOCSTRING = betterhelp.add_previews(DOCSTRING, SUB_DOCSTRINGS)
return betterhelp.subparser_main(argv, parser, DOCSTRING, SUB_DOCSTRINGS)
]]></content>
<tabTrigger>betterhelp_multi</tabTrigger>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.python</scope>
</snippet>

View file

@ -0,0 +1,18 @@
<snippet>
<content><![CDATA[
from voussoirkit import betterhelp
DOCSTRING = '''
$1
======
'''
return betterhelp.single_main(argv, parser, DOCSTRING)
]]></content>
<tabTrigger>betterhelp_single</tabTrigger>
<!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.python</scope>
</snippet>

View file

@ -11,5 +11,5 @@ if __name__ == '__main__':
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> --> <!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger --> <!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> --> <scope>source.python</scope>
</snippet> </snippet>

View file

@ -8,5 +8,5 @@ if __name__ == '__main__':
<!-- Optional: Set a tabTrigger to define how to trigger the snippet --> <!-- Optional: Set a tabTrigger to define how to trigger the snippet -->
<!-- <tabTrigger>hello</tabTrigger> --> <!-- <tabTrigger>hello</tabTrigger> -->
<!-- Optional: Set a scope to limit where the snippet will trigger --> <!-- Optional: Set a scope to limit where the snippet will trigger -->
<!-- <scope>source.python</scope> --> <scope>source.python</scope>
</snippet> </snippet>