diff --git a/dvc/command/cache.py b/dvc/command/cache.py index f1186a749..785bf40dc 100644 --- a/dvc/command/cache.py +++ b/dvc/command/cache.py @@ -1,12 +1,18 @@ import argparse +import logging from dvc.command import completion from dvc.command.base import append_doc_link, fix_subparsers from dvc.command.config import CmdConfig +logger = logging.getLogger(__name__) + class CmdCacheDir(CmdConfig): def run(self): + if self.args.value is None and not self.args.unset: + logger.info(self.config["cache"]["dir"]) + return 0 with self.config.edit(level=self.args.level) as edit: edit["cache"]["dir"] = self.args.value return 0 @@ -55,6 +61,8 @@ def add_parser(subparsers, parent_parser): "value", help="Path to cache directory. Relative paths are resolved relative " "to the current directory and saved to config relative to the " - "config file location.", + "config file location. If no path is provided, it returns the " + "current cache directory.", + nargs="?", ).complete = completion.DIR cache_dir_parser.set_defaults(func=CmdCacheDir) diff --git a/tests/func/test_cache.py b/tests/func/test_cache.py index 36e50ed22..98f8bfd6b 100644 --- a/tests/func/test_cache.py +++ b/tests/func/test_cache.py @@ -154,7 +154,7 @@ class TestCacheLinkType(TestDvc): class TestCmdCacheDir(TestDvc): def test(self): ret = main(["cache", "dir"]) - self.assertEqual(ret, 254) + self.assertEqual(ret, 0) def test_abs_path(self): dname = os.path.join(os.path.dirname(self._root_dir), "dir")