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

Commit 380926f

Browse files
committed
Add --default-no flag, adjust README
1 parent bf002a0 commit 380926f

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
@@ -49,6 +49,8 @@ Options (all optional) include:
4949
matching file extensions passed in --extensions
5050
--accept-all
5151
Automatically accept all changes (use with caution)
52+
--default-no
53+
Set default behavior to reject the change.
5254
--editor
5355
Specify an editor, e.g. "vim" or "emacs". If omitted, defaults to $EDITOR
5456
environment variable.

src/codemod.py

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

95-
def run_interactive(query, editor=None, just_count=False):
95+
def run_interactive(query, editor=None, just_count=False, default_no=False):
9696
"""
9797
Asks the user about each patch suggested by the result of the query.
9898
@@ -128,7 +128,7 @@ def run_interactive(query, editor=None, just_count=False):
128128

129129
for patch in suggestions:
130130
_save_bookmark(patch.start_position)
131-
_ask_about_patch(patch, editor)
131+
_ask_about_patch(patch, editor, default_no)
132132
print 'Searching...'
133133
_delete_bookmark()
134134
if yes_to_all:
@@ -567,8 +567,9 @@ def print_file_line(line_number):
567567
print_file_line(i)
568568

569569
yes_to_all = False
570-
def _ask_about_patch(patch, editor):
570+
def _ask_about_patch(patch, editor, default_no):
571571
global yes_to_all
572+
default_action = 'n' if default_no else 'y'
572573
terminal_clear()
573574
terminal_print('%s\n' % patch.render_range(), color='WHITE')
574575
print
@@ -580,9 +581,13 @@ def _ask_about_patch(patch, editor):
580581

581582
if patch.new_lines is not None:
582583
if not yes_to_all:
583-
print 'Accept change (y = yes [default], n = no, e = edit, \
584-
A = yes to all, E = yes+edit)? ',
585-
p = _prompt('yneEA', default='y')
584+
if default_no:
585+
print ('Accept change (y = yes, n = no [default], e = edit, ' +
586+
'A = yes to all, E = yes+edit)? '),
587+
else:
588+
print ('Accept change (y = yes [default], n = no, e = edit, ' +
589+
'A = yes to all, E = yes+edit)? '),
590+
p = _prompt('yneEA', default=default_action)
586591
else:
587592
p = 'y'
588593
else:
@@ -810,6 +815,9 @@ def _parse_command_line():
810815
parser.add_argument('--accept-all', action='store_true',
811816
help='Automatically accept all changes (use with caution).')
812817

818+
parser.add_argument('--default-no', action='store_true',
819+
help='If set, this will make the default option to not accept the change.')
820+
813821
parser.add_argument('--editor', action='store', type=str,
814822
help='Specify an editor, e.g. "vim" or emacs". '
815823
'If omitted, defaults to $EDITOR environment variable.')
@@ -857,6 +865,7 @@ def _parse_command_line():
857865
if arguments.editor is not None:
858866
options['editor'] = arguments.editor
859867
options['just_count'] = arguments.count
868+
options['default_no'] = arguments.default_no
860869

861870
return options
862871

0 commit comments

Comments
 (0)