From 1d550f35af41239884db9dcba3869e6305f2ce3a Mon Sep 17 00:00:00 2001 From: girish joshi Date: Mon, 12 Oct 2020 11:21:38 +0530 Subject: [PATCH] command: print the current cache directory when no cmd flags are provided (#4613) * command: print the current cache directory when no cmd flags are provided tests: corrected the test for cache dir cmomand comamnd 'dvc cache dir' now prints the current cache dir when no cmd flags are provided and modified existing test for the same. Fixes #1998 Signed-off-by: Girish Joshi * command: updated validation for args.value and args.unset flag according to current convention in dvc/command/cache.py Signed-off-by: Girish Joshi * Update dvc/command/cache.py * dont forget logger Co-authored-by: Ruslan Kuprieiev Co-authored-by: Ruslan Kuprieiev --- dvc/command/cache.py | 10 +++++++++- tests/func/test_cache.py | 2 +- 2 files changed, 10 insertions(+), 2 deletions(-) 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")