Skip to content

Commit 41fa884

Browse files
committed
Added a cli arguments which will be displayed after the deltas are compared
Signed-off-by: Pratikrocks <pratikrocks.dey11@gmail.com>
1 parent 6778882 commit 41fa884

3 files changed

Lines changed: 45 additions & 5 deletions

File tree

src/deltacode/__init__.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,26 @@ def to_dict(self):
345345
('new', new_file),
346346
('old', old_file),
347347
])
348+
def __str__(self):
349+
350+
if self.old_file:
351+
old_file_path = self.old_file.original_path
352+
else:
353+
old_file_path = "null"
354+
355+
if self.new_file:
356+
new_file_path = self.new_file.original_path
357+
else:
358+
new_file_path = "null"
359+
360+
return (" {\n"+
361+
" status: " + str(self.status) + "\n"
362+
" factors: [" + ", ".join(self.factors) + "]\n" +
363+
" score: " + str(self.score) + "\n"+
364+
" new_file: " + new_file_path + "\n"+
365+
" old_file: " + old_file_path + "\n" +
366+
" }\n"
367+
)
348368

349369
class Stat(object):
350370
"""

src/deltacode/cli.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,31 @@ def write_json(deltacode, outfile, all_delta_types=False):
5050
('deltas_count', len([d for d in deltas(deltacode, all_delta_types)])),
5151
('delta_stats', deltacode.stats.to_dict()),
5252
('deltas', deltas(deltacode, all_delta_types))
53-
])
53+
])
54+
55+
try:
56+
57+
simplejson.dump(results, outfile, iterable_as_array=True, indent=2)
58+
outfile.write('\n')
59+
if outfile.name != '<stdout>' :
60+
"This condition arises when we are required to print in the json file and the value of -j in not the console terminal"
61+
click.echo('deltas_count: {}'.format(len([d for d in deltas(deltacode, all_delta_types)])))
62+
click.echo('delta_stats: ')
63+
for stat in deltacode.stats.to_dict():
64+
click.echo(""" "{}": {}""".format(str(stat),deltacode.stats.to_dict()[stat]))
65+
# TODO: add toggle for pretty printing
66+
67+
delta_count = 1
68+
for delta in deltacode.deltas :
69+
if delta.status != "unmodified":
70+
click.echo("delta {}".format(delta_count))
71+
click.echo(delta)
72+
delta_count += 1
5473

55-
# TODO: add toggle for pretty printing
56-
simplejson.dump(results, outfile, iterable_as_array=True, indent=2)
57-
outfile.write('\n')
74+
except Exception as e:
75+
"This exception arises when outfile has no name attribute"
76+
simplejson.dump(results, outfile, iterable_as_array=True, indent=2)
77+
outfile.write('\n')
5878

5979

6080
def print_version(ctx, param, value):

src/deltacode/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ def get_notice():
275275
delimiter = '\n\n\n'
276276
[notice_text, extra_notice_text] = notice_text.split(delimiter, 1)
277277
extra_notice_text = delimiter + extra_notice_text
278-
278+
279279
delimiter = '\n\n '
280280
[notice_text, acknowledgment_text] = notice_text.split(delimiter, 1)
281281
acknowledgment_text = delimiter + acknowledgment_text

0 commit comments

Comments
 (0)