コード例 #1
0
 def process_option(keyval):
     key, value = keyval.split('=', 2)
     parts = key.split('.')
     try:
         setting = self.config_root.find_setting(parts)
     except KeyError:
         setting = None
     if setting is None:
         exit_warning(
             _('ERROR: Unknown config option: “{}”').format(key))
     setting.value_from_cliarg = value
コード例 #2
0
 def die_write_failed(config_obj, err):
     hint = extract_hint(err)
     msg = _(
         '{}: {} “{}”: “{}”{}'
     ).format(
         _('ERROR'),
         _('Failed to write file at'),
         config_obj.filename,
         str(err),
         ' ({})'.format(hint) if hint else '',
     )
     exit_warning(msg)
コード例 #3
0
    def create_config(self, force):
        if not self.config_path:
            # It's up to the DEV to ensure this.
            raise AttributeError('ConfigUrable missing ‘config_path’')

        cfgfile_exists = os.path.exists(self.config_path)
        if cfgfile_exists and not force:
            exit_warning(_('Config file exists'))

        self.reset_config()
        click_echo(
            _('Initialized default config file at {}').format(
                highlight_value(self.config_path), ))
コード例 #4
0
 def exit_duplicates(err):
     msg = _(
         'ERROR: Your config file at “{}” has a duplicate setting: “{}”'
     ).format(configfile_path, str(err))
     exit_warning(msg)
コード例 #5
0
 def exit_parse_error(err):
     msg = _(
         'ERROR: Your config file at “{}” has a syntax error: “{}”'
     ).format(configfile_path, str(err))
     exit_warning(msg)
コード例 #6
0
def test_exit_warning(click_echo_mock):
    with pytest.raises(SystemExit):
        exit_warning('foo')
    assert click_echo_mock.called