diff --git a/dvc/command/run.py b/dvc/command/run.py index 1a3ac6d6d0..e011d625b1 100644 --- a/dvc/command/run.py +++ b/dvc/command/run.py @@ -159,9 +159,7 @@ def add_parser(subparsers, parent_parser): metavar="", ) run_parser.add_argument( - "--file", - help="Specify name of the DVC-file this command will generate.", - metavar="", + "--file", metavar="", help=argparse.SUPPRESS, ) run_parser.add_argument( "-w", diff --git a/dvc/repo/run.py b/dvc/repo/run.py index 6cf8d8e723..eea3eb05d3 100644 --- a/dvc/repo/run.py +++ b/dvc/repo/run.py @@ -91,6 +91,12 @@ def run(self, fname=None, no_exec=False, single_stage=False, **kwargs): "`-n|--name` is incompatible with `--single-stage`" ) + if stage_name and fname: + raise InvalidArgumentError( + "`--file` is currently incompatible with `-n|--name` " + "and requires `--single-stage`" + ) + if not stage_name and not single_stage: raise InvalidArgumentError("`-n|--name` is required") diff --git a/tests/unit/repo/__init__.py b/tests/unit/repo/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/unit/repo/test_run.py b/tests/unit/repo/test_run.py new file mode 100644 index 0000000000..5f4d97c9ac --- /dev/null +++ b/tests/unit/repo/test_run.py @@ -0,0 +1,12 @@ +import pytest + +from dvc.exceptions import InvalidArgumentError + + +def test_file(tmp_dir, dvc): + msg = ( + "`--file` is currently incompatible with `-n|--name` " + "and requires `--single-stage`" + ) + with pytest.raises(InvalidArgumentError, match=msg): + dvc.run(fname="path/dvc.yaml", name="my", cmd="mycmd")