Improve argparse, betterhelp snippets.
This commit is contained in:
parent
6f9ec9a003
commit
f482b3dab9
7 changed files with 67 additions and 5 deletions
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
32
voussoir/betterhelp_multi.sublime-snippet
Normal file
32
voussoir/betterhelp_multi.sublime-snippet
Normal 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>
|
18
voussoir/betterhelp_single.sublime-snippet
Normal file
18
voussoir/betterhelp_single.sublime-snippet
Normal 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>
|
|
@ -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>
|
||||||
|
|
|
@ -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>
|
||||||
|
|
Loading…
Reference in a new issue