class CmdConfig(CmdBaseNoRepo): def __init__(self, args): super().__init__(args) self.config = Config(validate=False) def run(self): if self.args.list: if any((self.args.name, self.args.value, self.args.unset)): logger.error( "-l/--list can't be used together with any of these " "options: -u/--unset, name, value") return 1 conf = self.config.load_one(self.args.level) logger.info("\n".join(self._format_config(conf))) return 0 if self.args.name is None: logger.error("name argument is required") return 1 section, opt = self.args.name.lower().strip().split(".", 1) if self.args.value is None and not self.args.unset: conf = self.config.load_one(self.args.level) self._check(conf, section, opt) logger.info(conf[section][opt]) return 0 with self.config.edit(self.args.level) as conf: if self.args.unset: self._check(conf, section, opt) del conf[section][opt] else: self._check(conf, section) conf[section][opt] = self.args.value if self.args.name == "cache.type": logger.warning( "You have changed the 'cache.type' option. This doesn't update" " any existing workspace file links, but it can be done with:" "\n dvc checkout --relink") return 0 def _check(self, conf, section, opt=None): if section not in conf: msg = "section {} doesn't exist" raise ConfigError(msg.format(self.args.name)) if opt and opt not in conf[section]: msg = "option {} doesn't exist" raise ConfigError(msg.format(self.args.name)) @staticmethod def _format_config(config): for key, value in flatten(config).items(): yield f"{key}={value}"
class CmdConfig(CmdBaseNoRepo): def __init__(self, args): super().__init__(args) self.config = Config(validate=False) def run(self): section, opt = self.args.name.lower().strip().split(".", 1) if self.args.value is None and not self.args.unset: conf = self.config.load_one(self.args.level) self._check(conf, section, opt) logger.info(conf[section][opt]) return 0 with self.config.edit(self.args.level) as conf: if self.args.unset: self._check(conf, section, opt) del conf[section][opt] else: self._check(conf, section) conf[section][opt] = self.args.value if self.args.name == "cache.type": logger.warning( "You have changed the 'cache.type' option. This doesn't update" " any existing workspace file links, but it can be done with:" "\n dvc checkout --relink" ) return 0 def _check(self, conf, section, opt=None): if section not in conf: msg = "section {} doesn't exist" raise ConfigError(msg.format(self.args.name)) if opt and opt not in conf[section]: msg = "option {} doesn't exist" raise ConfigError(msg.format(self.args.name))