Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Update core for latest knack #8940

Merged
merged 2 commits into from Apr 2, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion src/azure-cli-core/azure/cli/core/_config.py
Expand Up @@ -11,4 +11,3 @@
CONFIG_FILE_NAME = 'config'
GLOBAL_CONFIG_PATH = os.path.join(GLOBAL_CONFIG_DIR, CONFIG_FILE_NAME)
ENV_VAR_PREFIX = 'AZURE'
DEFAULTS_SECTION = 'defaults'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a "breaking change" but I suppose it can't be helped.

34 changes: 4 additions & 30 deletions src/azure-cli-core/azure/cli/core/commands/__init__.py
Expand Up @@ -121,23 +121,10 @@ def __init__(self, loader, name, handler, description=None, table_transformer=No
self.command_kwargs = kwargs

def _resolve_default_value_from_cfg_file(self, arg, overrides):
from azure.cli.core._config import DEFAULTS_SECTION
from azure.cli.core.commands.validators import DefaultStr

if not hasattr(arg.type, 'required_tooling'):
required = arg.type.settings.get('required', False)
setattr(arg.type, 'required_tooling', required)
if 'configured_default' in overrides.settings:
def_config = overrides.settings.pop('configured_default', None)
setattr(arg.type, 'default_name_tooling', def_config)
# same blunt mechanism like we handled id-parts, for create command, no name default
if self.name.split()[-1] == 'create' and overrides.settings.get('metavar', None) == 'NAME':
return
config_value = self.cli_ctx.config.get(DEFAULTS_SECTION, def_config, None)
if config_value:
logger.info("Configured default '%s' for arg %s", config_value, arg.name)
overrides.settings['default'] = DefaultStr(config_value)
overrides.settings['required'] = False
# same blunt mechanism like we handled id-parts, for create command, no name default
if self.name.split()[-1] == 'create' and overrides.settings.get('metavar', None) == 'NAME':
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we ignore defaults for create commands previously?

return
super(AzCliCommand, self)._resolve_default_value_from_cfg_file(arg, overrides)

def load_arguments(self):
super(AzCliCommand, self).load_arguments()
Expand All @@ -154,19 +141,6 @@ def load_arguments(self):
help='Do not wait for the long-running operation to finish.')))
self.arguments.update(cmd_args)

def update_argument(self, param_name, argtype):
from azure.cli.core.commands.validators import DefaultStr, DefaultInt
arg = self.arguments[param_name]
self._resolve_default_value_from_cfg_file(arg, argtype)
arg.type.update(other=argtype)
arg_default = arg.type.settings.get('default', None)
if isinstance(arg_default, str):
arg_default = DefaultStr(arg_default)
elif isinstance(arg_default, int):
arg_default = DefaultInt(arg_default)
if arg_default:
arg.type.settings['default'] = arg_default

def __call__(self, *args, **kwargs):
return self.handler(*args, **kwargs)

Expand Down
17 changes: 1 addition & 16 deletions src/azure-cli-core/azure/cli/core/commands/validators.py
Expand Up @@ -10,6 +10,7 @@
from azure.cli.core.profiles import ResourceType

from knack.log import get_logger
from knack.validators import DefaultStr, DefaultInt # pylint: disable=unused-import
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid the breaking change to core that would occur if these were removed.


logger = get_logger(__name__)

Expand Down Expand Up @@ -118,19 +119,3 @@ def _dest_to_option(dest):
forbidden_string = ', '.join(_dest_to_option(x) for x in included_forbidden)
error = '{}\n\tnot applicable: {}'.format(error, forbidden_string)
raise CLIError(error)


class DefaultStr(str):

def __new__(cls, *args, **kwargs):
instance = str.__new__(cls, *args, **kwargs)
instance.is_default = True
return instance


class DefaultInt(int):

def __new__(cls, *args, **kwargs):
instance = int.__new__(cls, *args, **kwargs)
instance.is_default = True
return instance

This file was deleted.

2 changes: 1 addition & 1 deletion src/azure-cli-core/setup.py
Expand Up @@ -59,7 +59,7 @@
'colorama>=0.3.9',
'humanfriendly>=4.7',
'jmespath',
'knack>=0.5.3',
'knack>=0.5.4',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While we're at it, should we use the ~= operator instead of the >= operator? Especially when libraries are in the 0 band, we want to protect ourselves from breaking changes (even if we're the ones who would be doing it.)

'msrest>=0.4.4',
'msrestazure>=0.4.25',
'paramiko>=2.0.8',
Expand Down
Expand Up @@ -129,12 +129,12 @@ def _handle_global_configuration(config):

def handle_configure(cmd, defaults=None):
if defaults:
from azure.cli.core._config import DEFAULTS_SECTION
defaults_section = cmd.cli_ctx.config.defaults_section_name
for default in defaults:
parts = default.split('=', 1)
if len(parts) == 1:
raise CLIError('usage error: --defaults STRING=STRING STRING=STRING ...')
cmd.cli_ctx.config.set_value(DEFAULTS_SECTION, parts[0], _normalize_config_value(parts[1]))
cmd.cli_ctx.config.set_value(defaults_section, parts[0], _normalize_config_value(parts[1]))
return

# if nothing supplied, we go interactively
Expand Down