mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-05 23:09:32 +01:00
* 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]>
69 lines
2.1 KiB
Python
69 lines
2.1 KiB
Python
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
|
|
|
|
|
|
def add_parser(subparsers, parent_parser):
|
|
from dvc.command.config import parent_config_parser
|
|
|
|
CACHE_HELP = "Manage cache settings."
|
|
|
|
cache_parser = subparsers.add_parser(
|
|
"cache",
|
|
parents=[parent_parser],
|
|
description=append_doc_link(CACHE_HELP, "cache"),
|
|
help=CACHE_HELP,
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
)
|
|
|
|
cache_subparsers = cache_parser.add_subparsers(
|
|
dest="cmd",
|
|
help="Use `dvc cache CMD --help` for command-specific " "help.",
|
|
)
|
|
|
|
fix_subparsers(cache_subparsers)
|
|
|
|
parent_cache_config_parser = argparse.ArgumentParser(
|
|
add_help=False, parents=[parent_config_parser]
|
|
)
|
|
CACHE_DIR_HELP = "Configure cache directory location."
|
|
|
|
cache_dir_parser = cache_subparsers.add_parser(
|
|
"dir",
|
|
parents=[parent_parser, parent_cache_config_parser],
|
|
description=append_doc_link(CACHE_HELP, "cache/dir"),
|
|
help=CACHE_DIR_HELP,
|
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
|
)
|
|
cache_dir_parser.add_argument(
|
|
"-u",
|
|
"--unset",
|
|
default=False,
|
|
action="store_true",
|
|
help="Unset option.",
|
|
)
|
|
cache_dir_parser.add_argument(
|
|
"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. If no path is provided, it returns the "
|
|
"current cache directory.",
|
|
nargs="?",
|
|
).complete = completion.DIR
|
|
cache_dir_parser.set_defaults(func=CmdCacheDir)
|