Skip to content

Commit 0381f31

Browse files
committed
added filter mechanism
1 parent 701bd20 commit 0381f31

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

bin/compose_diff

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ if __name__ == '__main__':
1111
parser.add_argument(
1212
'--images', action='store_const', const=True,
1313
help='diffs the images', default=False)
14+
parser.add_argument(
15+
'--filter', action='store',
16+
help='just consider specific items', default=None)
1417
parser.add_argument('files', nargs=argparse.REMAINDER)
1518
args = parser.parse_args()
1619

@@ -21,6 +24,6 @@ if __name__ == '__main__':
2124

2225
old, new = args.files[0], args.files[1]
2326

24-
ComposeDiff().diff_images(old, new)
27+
ComposeDiff().diff_images(old, new, args.filter)
2528
else:
2629
parser.print_help()

compose_diff/__init__.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,23 @@ class ComposeDiff:
77
def __init__(self):
88
pass
99

10-
def diff_images(self, old, new):
10+
def diff_images(self, old, new, filter):
1111
old = self.images(self.read(old))
1212
new = self.images(self.read(new))
1313

1414
print('| {0} | {1} |'.format('Name', 'Version'))
1515
print('| - | - |')
1616
for key in sorted(set(list(old.keys()) + list(new.keys()))):
17+
if filter is not None:
18+
if filter not in key:
19+
continue
1720
version = self.format_version(
1821
old=old[key] if key in old else None,
1922
new=new[key] if key in new else None)
2023

21-
print('| {0} | {1} |'.format(key, version))
24+
key = key.replace('_', '\_')
25+
version = version.replace('_', '\_')
26+
print('| {0} | {1} |'.format(key.split('/')[-1], version))
2227

2328
@staticmethod
2429
def format_version(old, new):
@@ -52,6 +57,7 @@ def images(data):
5257

5358
@staticmethod
5459
def split_image(data):
55-
if ':' not in data:
60+
if ':' not in data.split('/')[-1]:
5661
return data, 'latest'
57-
return data.split(':')
62+
splitted = data.split(':')
63+
return ':'.join(splitted[:-1]), splitted[-1]

features/images.feature

+27
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,30 @@ Feature: Images
3636
| three | 1 (new) |
3737
| two | 2 (1) |
3838
"""
39+
40+
Scenario: Filter
41+
Given a file named "A.yml" with:
42+
"""
43+
version: "2"
44+
services:
45+
one:
46+
image: one:1
47+
two:
48+
image: two:1
49+
"""
50+
And a file named "B.yml" with:
51+
"""
52+
version: "2"
53+
services:
54+
one:
55+
image: one:2
56+
two:
57+
image: two:2
58+
"""
59+
When I run `bin/compose_diff --images --filter one A.yml B.yml`
60+
Then it should pass with exactly:
61+
"""
62+
| Name | Version |
63+
| - | - |
64+
| one | 2 (1) |
65+
"""

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def readme():
88

99
setup(
1010
name='compose_diff',
11-
version='0.1.0',
11+
version='0.2.0',
1212
description='diff docker-compose files',
1313
long_description=readme(),
1414
url='http://github.com/funkwerk/compose_diff',

0 commit comments

Comments
 (0)