mirror of
				https://github.com/nvbn/thefuck.git
				synced 2025-10-31 15:12:20 +00:00 
			
		
		
		
	Add reboot confirmation dialog
This is kinda rough, I think this could be fleshed out more to be easier to add on to and have a clearer output.
This commit is contained in:
		| @@ -6,7 +6,7 @@ from .. import logs, types, const | ||||
| from ..conf import settings | ||||
| from ..corrector import get_corrected_commands | ||||
| from ..exceptions import EmptyCommand | ||||
| from ..ui import select_command | ||||
| from ..ui import select_command, confirm_command | ||||
| from ..utils import get_alias, get_all_executables | ||||
|  | ||||
|  | ||||
| @@ -41,8 +41,13 @@ def fix_command(known_args): | ||||
|  | ||||
|         corrected_commands = get_corrected_commands(command) | ||||
|         selected_command = select_command(corrected_commands) | ||||
|          | ||||
|  | ||||
|         if selected_command: | ||||
|         confirmation = True | ||||
|         if selected_command.script == "reboot": | ||||
|             confirmation = confirm_command("Reboot System?") | ||||
|          | ||||
|         if selected_command and confirmation: | ||||
|             selected_command.run(command) | ||||
|         else: | ||||
|             sys.exit(1) | ||||
|   | ||||
| @@ -6,6 +6,7 @@ from .exceptions import NoRuleMatched | ||||
| from .system import get_key | ||||
| from .utils import get_alias | ||||
| from . import logs, const | ||||
| from .types import CorrectedCommand | ||||
|  | ||||
|  | ||||
| def read_actions(): | ||||
| @@ -93,3 +94,26 @@ def select_command(corrected_commands): | ||||
|         elif action == const.ACTION_NEXT: | ||||
|             selector.next() | ||||
|             logs.confirm_text(selector.value) | ||||
|  | ||||
| def confirm_command(confirmation_text): | ||||
|     """Returns: | ||||
|  | ||||
|      - the first command when confirmation disabled; | ||||
|      - None when ctrl+c pressed; | ||||
|      - selected command. | ||||
|  | ||||
|     :type corrected_commands: Iterable[thefuck.types.CorrectedCommand] | ||||
|     :rtype: thefuck.types.CorrectedCommand | None | ||||
|  | ||||
|     """ | ||||
|  | ||||
|     logs.confirm_text(CorrectedCommand(confirmation_text,None,0)) | ||||
|  | ||||
|     action = read_actions() | ||||
|     for action in read_actions(): | ||||
|         if action == const.ACTION_SELECT: | ||||
|             sys.stderr.write('\n') | ||||
|             return True | ||||
|         elif action == const.ACTION_ABORT: | ||||
|             logs.failed('\nAborted') | ||||
|             return False | ||||
|   | ||||
		Reference in New Issue
	
	Block a user