Merge pull request #886 from efiop/master

dvc: add confirmation for `dvc destroy`
This commit is contained in:
Ruslan Kuprieiev
2018-07-15 19:27:30 +03:00
committed by GitHub
4 changed files with 56 additions and 1 deletions
+5
View File
@@ -94,6 +94,11 @@ def parse_args(argv=None):
'destroy',
parents=[parent_parser],
help='Destroy dvc')
destroy_parser.add_argument('-f',
'--force',
action='store_true',
default=False,
help='Force destruction')
destroy_parser.set_defaults(func=CmdDestroy)
+12 -1
View File
@@ -1,9 +1,20 @@
from dvc.command.common.base import CmdBase
from dvc.prompt import prompt
class CmdDestroy(CmdBase):
def run(self):
def run_cmd(self):
try:
msg = u'This will destroy all information about your pipelines as ' \
u'well as cache in .dvc/cache.\n' \
u'Are you sure you want to continue?'
if not self.args.force and not prompt(msg, False):
err = u'Cannot destroy without a confirmation from the user. ' \
u'Use \'-f\' to force.'
self.project.logger.error(err)
return 1
self.project.destroy()
except Exception as exc:
self.project.logger.error('Failed to destroy DVC', exc)
+18
View File
@@ -0,0 +1,18 @@
import sys
try:
# NOTE: in Python3 raw_input() was renamed to input()
input = raw_input
except NameError:
pass
def prompt(msg, default=False):
if not sys.stdout.isatty():
return default
answer = input(msg + u'\n').lower()
while answer not in ['yes', 'no', 'y', 'n']:
answer = input('Enter \'yes\' or \'no\'.\n').lower()
return answer[0] == "y"
+21
View File
@@ -0,0 +1,21 @@
import os
from dvc.main import main
from tests.test_repro import TestRepro
class TestDestroyNoConfirmation(TestRepro):
def test(self):
ret = main(['destroy'])
self.assertNotEqual(ret, 0)
class TestDestroyForce(TestRepro):
def test(self):
ret = main(['destroy', '-f'])
self.assertEqual(ret, 0)
self.assertFalse(os.path.exists(self.dvc.dvc_dir))
self.assertFalse(os.path.exists(self.file1_stage))
self.assertFalse(os.path.exists(self.file1))