Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add a new line after output and introduce the --pk-only flag

  • Loading branch information...
commit d3f32c017555686b2d3b0d3af89ae777a8c375a4 1 parent 00ea599
@uberj uberj authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 invtool/main.py
View
16 invtool/main.py
@@ -1,4 +1,5 @@
import argparse
+import simplejson as json
enabled_dispatches = [
'invtool.dns_dispatch',
@@ -35,6 +36,11 @@ def main(args):
'--debug', default=False, dest='DEBUG', action='store_true',
help="Print stuff"
)
+ format_group.add_argument(
+ '--pk-only', default=False, dest='p_pk_only', action='store_true',
+ help="If an object was just update/created print the primary key"
+ "of that object otherwise print nothing. No new line is printed."
+ )
base_parser = inv_parser.add_subparsers(dest='dtype')
# Build parsers. Parses should register arguments.
@@ -42,7 +48,15 @@ def main(args):
d.build_parser(base_parser)
nas = inv_parser.parse_args(args[1:])
+ if nas.p_pk_only:
+ nas.p_json = True
resp_code, resp_list = dispatch(nas)
if not nas.p_silent and resp_list:
- print '\n'.join(resp_list),
+ if nas.p_pk_only:
+ ret_json = json.loads('\n'.join(resp_list))
+ if 'pk' in ret_json:
+ print ret_json['pk'],
+ else:
+ print '\n'.join(resp_list)
+ print
return resp_code
Please sign in to comment.
Something went wrong with that request. Please try again.