Index: git_footers.py |
diff --git a/git_footers.py b/git_footers.py |
index 4641f7470f551babbe8edb1938c21676e320f20d..4425966407eb19f5cd1553979ce04284c8d21d7b 100755 |
--- a/git_footers.py |
+++ b/git_footers.py |
@@ -4,6 +4,7 @@ |
# found in the LICENSE file. |
import argparse |
+import json |
import re |
import sys |
@@ -163,7 +164,8 @@ def main(args): |
parser = argparse.ArgumentParser( |
formatter_class=argparse.ArgumentDefaultsHelpFormatter |
) |
- parser.add_argument('ref') |
+ parser.add_argument('ref', nargs='?', help="Git ref to retrieve footers from." |
+ " Omit to parse stdin.") |
g = parser.add_mutually_exclusive_group() |
g.add_argument('--key', metavar='KEY', |
@@ -172,11 +174,16 @@ def main(args): |
g.add_argument('--position', action='store_true') |
g.add_argument('--position-ref', action='store_true') |
g.add_argument('--position-num', action='store_true') |
+ g.add_argument('--json', help="filename to dump JSON serialized headers to.") |
opts = parser.parse_args(args) |
- message = git.run('log', '-1', '--format=%B', opts.ref) |
+ if opts.ref: |
+ message = git.run('log', '-1', '--format=%B', opts.ref) |
+ else: |
+ message = '\n'.join(l for l in sys.stdin) |
iannucci
2016/05/23 19:52:33
isn't this just sys.stdin.read().strip('\n')?
martiniss
2016/05/23 21:30:01
You can't mock out sys.stdin.read with StringIO, s
|
+ |
footers = parse_footers(message) |
if opts.key: |
@@ -191,10 +198,12 @@ def main(args): |
pos = get_position(footers) |
assert pos[1], 'No valid position for commit' |
print pos[1] |
+ elif opts.json: |
+ with open(opts.json, 'w') as f: |
+ json.dump(footers, f) |
else: |
- for k in footers.keys(): |
- for v in footers[k]: |
- print '%s: %s' % (k, v) |
+ for k, v in footers.items(): |
+ print '%s: %s' % (k, v) |
iannucci
2016/05/23 19:52:33
this change is not orthographic. Previously this w
martiniss
2016/05/23 21:30:01
Ah whoops, I thought I was optimizing ;) changed b
|
return 0 |