Update and unify my boilerplate snippets.

This commit is contained in:
voussoir 2021-05-06 19:32:37 -07:00
parent 1d48427f72
commit bc45143dbf
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB
8 changed files with 74 additions and 136 deletions

View file

@ -1,35 +0,0 @@
<snippet>
<content><![CDATA[
import argparse
import sys
from voussoirkit import vlogging
log = vlogging.getLogger(__name__, '$1')
def $2_argparse(args):
return $2()
def main(argv):
argv = vlogging.set_level_by_argv(log, argv)
parser = argparse.ArgumentParser(description=__doc__)
subparsers = parser.add_subparsers()
p_$2 = subparsers.add_parser('$2')
p_$2.add_argument('required_positional')
p_$2.add_argument('optional_positional', nargs='?', default=None)
p_$2.add_argument('-k', '--kwarg', dest='kwarg', default=None)
p_$2.add_argument('-b', '--boolkwarg', dest='boolkwarg', action='store_true')
p_$2.set_defaults(func=$2_argparse)
args = parser.parse_args(argv)
return args.func(args)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))
]]></content>
<tabTrigger>argparse_multi</tabTrigger>
<scope>source.python</scope>
</snippet>

View file

@ -3,8 +3,8 @@
p_$1 = subparsers.add_parser('$1')
p_$1.add_argument('required_positional')
p_$1.add_argument('optional_positional', nargs='?', default=None)
p_$1.add_argument('-k', '--kwarg', dest='kwarg', default=None)
p_$1.add_argument('-b', '--boolkwarg', dest='boolkwarg', action='store_true')
p_$1.add_argument('--kwarg', default=None)
p_$1.add_argument('--boolkwarg', action='store_true')
p_$1.set_defaults(func=$1_argparse)
]]></content>
<tabTrigger>subparser</tabTrigger>

View file

@ -1,32 +0,0 @@
<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

@ -1,18 +0,0 @@
<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

@ -0,0 +1,57 @@
<snippet>
<content><![CDATA[
'''
$1
======
{$2}
TO SEE DETAILS ON EACH COMMAND, RUN
> $1.py <command> --help
'''
SUB_DOCSTRINGS = dict(
$2='''
$2:
Command description.
'''.strip(),
)
import argparse
import sys
from voussoirkit import betterhelp
from voussoirkit import operatornotify
from voussoirkit import vlogging
log = vlogging.getLogger(__name__, '$1')
def $2_argparse(args):
return 0
__doc__ = betterhelp.add_previews(__doc__, SUB_DOCSTRINGS)
def main(argv):
argv = vlogging.set_level_by_argv(log, argv)
(opnot_context, argv) = operatornotify.main_log_context(argv, subject='$1 warnings')
parser = argparse.ArgumentParser(description=__doc__)
subparsers = parser.add_subparsers()
p_$2 = subparsers.add_parser('$2')
p_$2.add_argument('required_positional')
p_$2.add_argument('optional_positional', nargs='?', default=None)
p_$2.add_argument('--kwarg', default=None)
p_$2.add_argument('--boolkwarg', action='store_true')
p_$2.set_defaults(func=$2_argparse)
with opnot_context:
return betterhelp.subparser_main(argv, parser, __doc__, SUB_DOCSTRINGS)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))
]]></content>
<tabTrigger>boilerplate_multi</tabTrigger>
<scope>source.python</scope>
<description>boilerplate multi</description>
</snippet>

View file

@ -1,33 +1,41 @@
<snippet>
<content><![CDATA[
'''
$1
======
'''
import argparse
import sys
from voussoirkit import betterhelp
from voussoirkit import operatornotify
from voussoirkit import vlogging
log = vlogging.getLogger(__name__, '$1')
def $1_argparse(args):
return $1()
return 0
def main(argv):
argv = vlogging.set_level_by_argv(log, argv)
(opnot_context, argv) = operatornotify.main_log_context(argv, subject='$1 warnings')
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('required_positional')
parser.add_argument('optional_positional', nargs='?', default=None)
parser.add_argument('-k', '--kwarg', dest='kwarg', default=None)
parser.add_argument('-b', '--boolkwarg', dest='boolkwarg', action='store_true')
parser.add_argument('--kwarg', default=None)
parser.add_argument('--boolkwarg', action='store_true')
parser.set_defaults(func=$1_argparse)
args = parser.parse_args(argv)
return args.func(args)
with opnot_context:
return betterhelp.single_main(argv, parser, __doc__)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))
]]></content>
<tabTrigger>argparse</tabTrigger>
<tabTrigger>boilerplate</tabTrigger>
<scope>source.python</scope>
<description>boilerplate single</description>
</snippet>

View file

@ -1,42 +0,0 @@
<snippet>
<content><![CDATA[
from voussoirkit import betterhelp
DOCSTRING = '''
____my__program____
{____my__command____}
TO SEE DETAILS ON EACH COMMAND, RUN
> ____my__program____.py <command> --help
'''.lstrip()
SUB_DOCSTRINGS = dict(
____my__command____='''
____my__command____:
____my__command____description
> ____my__program____.py ____my__command____
flags:
--____my__flag____:
'''.strip(),
)
DOCSTRING = betterhelp.add_previews(DOCSTRING, SUB_DOCSTRINGS)
def main(argv):
return betterhelp.subparser_main(
argv,
parser,
main_docstring=DOCSTRING,
sub_docstrings=SUB_DOCSTRINGS,
)
]]></content>
<tabTrigger>helptext</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

@ -4,7 +4,7 @@ from voussoirkit import vlogging
log = vlogging.getLogger(__name__, '$1')
def main(argv):
# Put this at the top of main
argv = vlogging.set_level_by_argv(log, argv)
]]></content>