mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
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 <[email protected]> * command: updated validation for args.value and args.unset flag according to current convention in dvc/command/cache.py Signed-off-by: Girish Joshi <[email protected]> * Update dvc/command/cache.py * dont forget logger Co-authored-by: Ruslan Kuprieiev <[email protected]> Co-authored-by: Ruslan Kuprieiev <[email protected]>
This commit is contained in:
co-authored by
Ruslan Kuprieiev
Ruslan Kuprieiev
parent
fba94a4569
commit
1d550f35af
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user