From f482b3dab9f199529742202cf2c29fed093f7443 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 14 Jan 2021 02:30:40 -0800 Subject: [PATCH] Improve argparse, betterhelp snippets. --- voussoir/argparse.sublime-snippet | 8 +++++- voussoir/argparse_multi.sublime-snippet | 8 +++++- voussoir/argparse_subparser.sublime-snippet | 2 +- voussoir/betterhelp_multi.sublime-snippet | 32 +++++++++++++++++++++ voussoir/betterhelp_single.sublime-snippet | 18 ++++++++++++ voussoir/defmain.sublime-snippet | 2 +- voussoir/ifmain.sublime-snippet | 2 +- 7 files changed, 67 insertions(+), 5 deletions(-) create mode 100644 voussoir/betterhelp_multi.sublime-snippet create mode 100644 voussoir/betterhelp_single.sublime-snippet diff --git a/voussoir/argparse.sublime-snippet b/voussoir/argparse.sublime-snippet index d032f93..0101fbc 100644 --- a/voussoir/argparse.sublime-snippet +++ b/voussoir/argparse.sublime-snippet @@ -3,10 +3,16 @@ import argparse import sys +from voussoirkit import vlogging + +log = vlogging.getLogger(__name__) + def $1_argparse(args): return $1() def main(argv): + argv = vlogging.set_level_by_argv(log, argv) + parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('required_positional') @@ -26,5 +32,5 @@ if __name__ == '__main__': - + source.python diff --git a/voussoir/argparse_multi.sublime-snippet b/voussoir/argparse_multi.sublime-snippet index 7a1c4df..1e46e24 100644 --- a/voussoir/argparse_multi.sublime-snippet +++ b/voussoir/argparse_multi.sublime-snippet @@ -3,10 +3,16 @@ import argparse import sys +from voussoirkit import vlogging + +log = vlogging.getLogger(__name__) + def $1_argparse(args): return $1() def main(argv): + argv = vlogging.set_level_by_argv(log, argv) + parser = argparse.ArgumentParser(description=__doc__) subparsers = parser.add_subparsers() @@ -28,5 +34,5 @@ if __name__ == '__main__': - + source.python diff --git a/voussoir/argparse_subparser.sublime-snippet b/voussoir/argparse_subparser.sublime-snippet index 80bbf9d..33bddfc 100644 --- a/voussoir/argparse_subparser.sublime-snippet +++ b/voussoir/argparse_subparser.sublime-snippet @@ -11,5 +11,5 @@ p_$1.set_defaults(func=$1_argparse) - + source.python diff --git a/voussoir/betterhelp_multi.sublime-snippet b/voussoir/betterhelp_multi.sublime-snippet new file mode 100644 index 0000000..7a9684e --- /dev/null +++ b/voussoir/betterhelp_multi.sublime-snippet @@ -0,0 +1,32 @@ + + $1.py --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) + +]]> +betterhelp_multi + + + + source.python + diff --git a/voussoir/betterhelp_single.sublime-snippet b/voussoir/betterhelp_single.sublime-snippet new file mode 100644 index 0000000..549650d --- /dev/null +++ b/voussoir/betterhelp_single.sublime-snippet @@ -0,0 +1,18 @@ + + +betterhelp_single + + + + source.python + diff --git a/voussoir/defmain.sublime-snippet b/voussoir/defmain.sublime-snippet index da2f8c4..1d11cff 100644 --- a/voussoir/defmain.sublime-snippet +++ b/voussoir/defmain.sublime-snippet @@ -11,5 +11,5 @@ if __name__ == '__main__': - + source.python diff --git a/voussoir/ifmain.sublime-snippet b/voussoir/ifmain.sublime-snippet index 1dab679..a72195c 100644 --- a/voussoir/ifmain.sublime-snippet +++ b/voussoir/ifmain.sublime-snippet @@ -8,5 +8,5 @@ if __name__ == '__main__': - + source.python