run: introduce --force option

Signed-off-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
Ruslan Kuprieiev
2018-12-03 05:13:54 +02:00
parent 298ae356cd
commit e81c6f2b34
3 changed files with 27 additions and 5 deletions
+8 -1
View File
@@ -268,9 +268,16 @@ def parse_args(argv=None):
'--yes',
action='store_true',
default=False,
help="Automatic 'yes' answer to all prompts. E.g. "
help="(OBSOLETED, use --force instead) Automatic "
"'yes' answer to all prompts. E.g. "
"when '.dvc' file exists and dvc asks if you "
"want to overwrite it.")
run_parser.add_argument(
'--force',
action='store_true',
default=False,
help="Overwrite existing dvc file without asking "
"for confirmation.")
run_parser.add_argument(
'command',
nargs=argparse.REMAINDER,
+2 -4
View File
@@ -21,9 +21,6 @@ class CmdRun(CmdBase):
def run(self):
try:
if self.args.yes:
self.project.prompt.default = True
self.project.run(cmd=self._joined_cmd(),
outs=self.args.outs,
outs_no_cache=self.args.outs_no_cache,
@@ -31,7 +28,8 @@ class CmdRun(CmdBase):
deps=self.args.deps,
fname=self.args.file,
cwd=self.args.cwd,
no_exec=self.args.no_exec)
no_exec=self.args.no_exec,
overwrite=(self.args.yes or self.args.force))
except DvcException as ex:
self.project.logger.error('Failed to run command', ex)
return 1
+17
View File
@@ -185,6 +185,23 @@ class TestCmdRun(TestDvc):
self.assertEqual(ret, 252)
class TestCmdRunOverwrite(TestDvc):
def test(self):
ret = main(['run',
'-d', self.FOO,
'-d', self.CODE,
'-o', 'out',
'-f', 'out.dvc',
'python', self.CODE, self.FOO, 'out'])
self.assertEqual(ret, 0)
ret = main(['run',
'--force',
'-f', 'out.dvc',
'-d', self.BAR])
self.assertEqual(ret, 0)
class TestRunDeterministicBase(TestDvc):
def setUp(self):
super(TestRunDeterministicBase, self).setUp()