Skip to content
This repository was archived by the owner on Jun 10, 2021. It is now read-only.

Commit 560e394

Browse files
committed
Merge pull request #57 from keyan/kp_add_default_no
Add --default-no flag
2 parents 86a6670 + 380926f commit 560e394

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ Options (all optional) include:
5151
matching file extensions passed in --extensions
5252
--accept-all
5353
Automatically accept all changes (use with caution)
54+
--default-no
55+
Set default behavior to reject the change.
5456
--editor
5557
Specify an editor, e.g. "vim" or "emacs". If omitted, defaults to $EDITOR
5658
environment variable.

src/codemod.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def the_filter(path):
8989
extensions=['php', 'phpt', 'js', 'css', 'rb', 'erb']
9090
)
9191

92-
def run_interactive(query, editor=None, just_count=False):
92+
def run_interactive(query, editor=None, just_count=False, default_no=False):
9393
"""
9494
Asks the user about each patch suggested by the result of the query.
9595
@@ -125,7 +125,7 @@ def run_interactive(query, editor=None, just_count=False):
125125

126126
for patch in suggestions:
127127
_save_bookmark(patch.start_position)
128-
_ask_about_patch(patch, editor)
128+
_ask_about_patch(patch, editor, default_no)
129129
print 'Searching...'
130130
_delete_bookmark()
131131
if yes_to_all:
@@ -564,8 +564,9 @@ def print_file_line(line_number):
564564
print_file_line(i)
565565

566566
yes_to_all = False
567-
def _ask_about_patch(patch, editor):
567+
def _ask_about_patch(patch, editor, default_no):
568568
global yes_to_all
569+
default_action = 'n' if default_no else 'y'
569570
terminal_clear()
570571
terminal_print('%s\n' % patch.render_range(), color='WHITE')
571572
print
@@ -577,9 +578,13 @@ def _ask_about_patch(patch, editor):
577578

578579
if patch.new_lines is not None:
579580
if not yes_to_all:
580-
print 'Accept change (y = yes [default], n = no, e = edit, \
581-
A = yes to all, E = yes+edit)? ',
582-
p = _prompt('yneEA', default='y')
581+
if default_no:
582+
print ('Accept change (y = yes, n = no [default], e = edit, ' +
583+
'A = yes to all, E = yes+edit)? '),
584+
else:
585+
print ('Accept change (y = yes [default], n = no, e = edit, ' +
586+
'A = yes to all, E = yes+edit)? '),
587+
p = _prompt('yneEA', default=default_action)
583588
else:
584589
p = 'y'
585590
else:
@@ -807,6 +812,9 @@ def _parse_command_line():
807812
parser.add_argument('--accept-all', action='store_true',
808813
help='Automatically accept all changes (use with caution).')
809814

815+
parser.add_argument('--default-no', action='store_true',
816+
help='If set, this will make the default option to not accept the change.')
817+
810818
parser.add_argument('--editor', action='store', type=str,
811819
help='Specify an editor, e.g. "vim" or emacs". '
812820
'If omitted, defaults to $EDITOR environment variable.')
@@ -854,6 +862,7 @@ def _parse_command_line():
854862
if arguments.editor is not None:
855863
options['editor'] = arguments.editor
856864
options['just_count'] = arguments.count
865+
options['default_no'] = arguments.default_no
857866

858867
return options
859868

0 commit comments

Comments
 (0)