2019-04-17 01:39:00 +00:00
|
|
|
<snippet>
|
|
|
|
<content><![CDATA[
|
|
|
|
import argparse
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def $1_argparse(args):
|
2019-12-05 08:18:27 +00:00
|
|
|
return $1()
|
2019-04-17 01:39:00 +00:00
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
subparsers = parser.add_subparsers()
|
|
|
|
|
2020-01-29 03:31:38 +00:00
|
|
|
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.set_defaults(func=$1_argparse)
|
2019-04-17 01:39:00 +00:00
|
|
|
|
|
|
|
args = parser.parse_args(argv)
|
2019-12-05 08:18:27 +00:00
|
|
|
return args.func(args)
|
2019-04-17 01:39:00 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
raise SystemExit(main(sys.argv[1:]))
|
|
|
|
|
|
|
|
]]></content>
|
|
|
|
<tabTrigger>argparse_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>
|