From d0cb029116e4c045af85cf657e73491bef509385 Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Tue, 21 Jul 2020 11:53:01 +0800 Subject: [PATCH 01/12] config --- src/azure-cli-core/azure/cli/core/util.py | 5 +- .../cli/command_modules/config/__init__.py | 26 ++++++ .../azure/cli/command_modules/config/_help.py | 48 ++++++++++ .../cli/command_modules/config/_params.py | 25 ++++++ .../cli/command_modules/config/commands.py | 16 ++++ .../cli/command_modules/config/custom.py | 90 +++++++++++++++++++ .../command_modules/config/tests/__init__.py | 4 + .../config/tests/latest/__init__.py | 4 + .../config/tests/latest/test_config.py | 81 +++++++++++++++++ 9 files changed, 298 insertions(+), 1 deletion(-) create mode 100644 src/azure-cli/azure/cli/command_modules/config/__init__.py create mode 100644 src/azure-cli/azure/cli/command_modules/config/_help.py create mode 100644 src/azure-cli/azure/cli/command_modules/config/_params.py create mode 100644 src/azure-cli/azure/cli/command_modules/config/commands.py create mode 100644 src/azure-cli/azure/cli/command_modules/config/custom.py create mode 100644 src/azure-cli/azure/cli/command_modules/config/tests/__init__.py create mode 100644 src/azure-cli/azure/cli/command_modules/config/tests/latest/__init__.py create mode 100644 src/azure-cli/azure/cli/command_modules/config/tests/latest/test_config.py diff --git a/src/azure-cli-core/azure/cli/core/util.py b/src/azure-cli-core/azure/cli/core/util.py index 96c7f3f3031..bd9af35bc19 100644 --- a/src/azure-cli-core/azure/cli/core/util.py +++ b/src/azure-cli-core/azure/cli/core/util.py @@ -882,7 +882,7 @@ def _log_response(response, **kwargs): return response -class ConfiguredDefaultSetter: +class ScopedConfig(object): def __init__(self, cli_config, use_local_config=None): self.use_local_config = use_local_config @@ -899,6 +899,9 @@ def __exit__(self, exc_type, exc_val, exc_tb): setattr(self.cli_config, 'use_local_config', self.original_use_local_config) +ConfiguredDefaultSetter = ScopedConfig + + def _ssl_context(): if sys.version_info < (3, 4) or (in_cloud_console() and platform.system() == 'Windows'): try: diff --git a/src/azure-cli/azure/cli/command_modules/config/__init__.py b/src/azure-cli/azure/cli/command_modules/config/__init__.py new file mode 100644 index 00000000000..d06b78139f5 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/config/__init__.py @@ -0,0 +1,26 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azure.cli.core import AzCommandsLoader + +import azure.cli.command_modules.config._help # pylint: disable=unused-import + + +class ConfigCommandsLoader(AzCommandsLoader): + + def __init__(self, cli_ctx=None): + super(ConfigCommandsLoader, self).__init__(cli_ctx=cli_ctx) + + def load_command_table(self, args): + from azure.cli.command_modules.config.commands import load_command_table + load_command_table(self, args) + return self.command_table + + def load_arguments(self, command): + from azure.cli.command_modules.config._params import load_arguments + load_arguments(self, command) + + +COMMAND_LOADER_CLS = ConfigCommandsLoader diff --git a/src/azure-cli/azure/cli/command_modules/config/_help.py b/src/azure-cli/azure/cli/command_modules/config/_help.py new file mode 100644 index 00000000000..6d4181d1e56 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/config/_help.py @@ -0,0 +1,48 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from knack.help_files import helps # pylint: disable=unused-import +# pylint: disable=line-too-long, too-many-lines + +helps['config set'] = """ +type: command +short-summary: Set a configuration. +long-summary: For available configuration options, see https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration +examples: + - name: Disable color with `core.no_color`. + text: az config set core.no_color=true + - name: Hide warnings and only show errors with `core.only_show_errors`. + text: az config set core.only_show_errors=true + - name: Turn on client-side telemetry. + text: az config set core.collect_telemetry=true + - name: Turn on file logging and set its location. + text: |- + az config set logging.enable_log_file=true + az config set logging.log_dir=~/az-logs + - name: Set the default resource group to `myRG`. + text: az config set default.group=myRG + - name: Set the default resource group to `myRG` on a local scope. + text: az config set default.group=myRG --local +""" + +helps['config get'] = """ +type: command +short-summary: Get a configuration. +examples: + - name: Get all configurations. + text: az config get + - name: Get configurations in `core` section. + text: az config get core + - name: Get configuration of key `core.no_color`. + text: az config get core.no_color +""" + +helps['config unset'] = """ +type: command +short-summary: Unset a configuration. +examples: + - name: Unset configuration of key `core.no_color`. + text: az config unset core.no_color +""" diff --git a/src/azure-cli/azure/cli/command_modules/config/_params.py b/src/azure-cli/azure/cli/command_modules/config/_params.py new file mode 100644 index 00000000000..cca706a22cc --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/config/_params.py @@ -0,0 +1,25 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +# pylint: disable=line-too-long +from azure.cli.core.commands.parameters import get_enum_type, get_three_state_flag + + +def load_arguments(self, _): + + with self.argument_context('config set') as c: + c.positional('key_value', nargs='+', help="Space-separated configurations in the form of [section].[key]=[value].") + c.argument('local', action='store_true', help='Use the local config') + c.ignore('_subscription') # ignore the global subscription param + + with self.argument_context('config get') as c: + c.positional('key', nargs='?', help='The configuration in the form of [section].[key]=[value].') + c.argument('local', action='store_true', help='Use the local config') + c.ignore('_subscription') # ignore the global subscription param + + with self.argument_context('config unset') as c: + c.positional('key', nargs='+', help='The configuration in the form of [section].[key]=[value].') + c.argument('local', action='store_true', help='Use the local config') + c.ignore('_subscription') # ignore the global subscription param diff --git a/src/azure-cli/azure/cli/command_modules/config/commands.py b/src/azure-cli/azure/cli/command_modules/config/commands.py new file mode 100644 index 00000000000..094ce68e58d --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/config/commands.py @@ -0,0 +1,16 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from azure.cli.core.commands import CliCommandType + + +def load_command_table(self, _): + + config_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.config.custom#{}') + + with self.command_group('config', config_custom, is_experimental=True) as g: + g.command('set', 'config_set') + g.command('get', 'config_get') + g.command('unset', 'config_unset') diff --git a/src/azure-cli/azure/cli/command_modules/config/custom.py b/src/azure-cli/azure/cli/command_modules/config/custom.py new file mode 100644 index 00000000000..9c16a196cc5 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/config/custom.py @@ -0,0 +1,90 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from knack.log import get_logger +from knack.util import CLIError + +from azure.cli.core.util import ScopedConfig + +logger = get_logger(__name__) + + +def _normalize_config_value(value): + if value: + value = '' if value in ["''", '""'] else value + return value + + +def config_set(cmd, key_value=None, local=False): + from azure.cli.core.cloud import cloud_forbid_telemetry, get_active_cloud_name + if key_value: + defaults_section = cmd.cli_ctx.config.defaults_section_name + with ScopedConfig(cmd.cli_ctx.config, local): + for kv in key_value: + # core.no_color=true + parts = kv.split('=', 1) + if len(parts) == 1: + raise CLIError('usage error: [section].[name]=[value] ...') + key = parts[0] + value = parts[1] + + # core.no_color + parts = key.split('.', 1) + if len(parts) == 1: + raise CLIError('usage error: [section].[name]=[value] ...') + section = parts[0] + name = parts[1] + + cmd.cli_ctx.config.set_value(section, name, _normalize_config_value(value)) + + +def config_get(cmd, key=None, local=False): + # No arg. List all sections and all items + if not key: + with ScopedConfig(cmd.cli_ctx.config, local): + sections = cmd.cli_ctx.config.sections() + result = {} + for section in sections: + items = cmd.cli_ctx.config.items(section) + result[section] = items + return result + + parts = key.split('.', 1) + if len(parts) == 1: + # Only section is provided + section = key + name = None + else: + # section.name + section = parts[0] + name = parts[1] + + with ScopedConfig(cmd.cli_ctx.config, local): + items = cmd.cli_ctx.config.items(section) + + if not name: + # Only section + return items + else: + # section.option + try: + return next(x for x in items if x['name']==name) + except StopIteration: + raise CLIError("Configuration '{}' is not set.".format(key)) + + +def config_unset(cmd, key=None, local=False): + for k in key: + # section.name + parts = k.split('.', 1) + + if len(parts) == 1: + raise CLIError("usage error: [section].[name]") + else: + section = parts[0] + name = parts[1] + + with ScopedConfig(cmd.cli_ctx.config, local): + cmd.cli_ctx.config.remove_option(section, name) diff --git a/src/azure-cli/azure/cli/command_modules/config/tests/__init__.py b/src/azure-cli/azure/cli/command_modules/config/tests/__init__.py new file mode 100644 index 00000000000..34913fb394d --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/config/tests/__init__.py @@ -0,0 +1,4 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- diff --git a/src/azure-cli/azure/cli/command_modules/config/tests/latest/__init__.py b/src/azure-cli/azure/cli/command_modules/config/tests/latest/__init__.py new file mode 100644 index 00000000000..34913fb394d --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/config/tests/latest/__init__.py @@ -0,0 +1,4 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- diff --git a/src/azure-cli/azure/cli/command_modules/config/tests/latest/test_config.py b/src/azure-cli/azure/cli/command_modules/config/tests/latest/test_config.py new file mode 100644 index 00000000000..b86290f8f71 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/config/tests/latest/test_config.py @@ -0,0 +1,81 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- +import os +import tempfile +import unittest +from unittest.mock import MagicMock + +from azure.cli.testsdk import ScenarioTest, LocalContextScenarioTest +from knack.util import CLIError + + +class ConfigTest(ScenarioTest): + + def test_config(self): + + # [test_section1] + # test_option1 = test_value1 + # + # [test_section2] + # test_option21 = test_value21 + # test_option22 = test_value22 + + # C:\Users\{username}\AppData\Local\Temp + tempdir = tempfile.gettempdir() + original_path = os.getcwd() + os.chdir(tempdir) + print("Using temp dir: {}".format(tempdir)) + + global_test_args = {"source": os.path.expanduser('~\\.azure\\config'), "flag": ""} + local_test_args = {"source": os.path.join(tempdir, '.azure\\config'), "flag": " --local"} + + for args in (global_test_args, local_test_args): + test_option1_expected = {'name': 'test_option1', 'source': args["source"], 'value': 'test_value1'} + test_option21_expected = {'name': 'test_option21', 'source': args["source"], 'value': 'test_value21'} + test_option22_expected = {'name': 'test_option22', 'source': args["source"], 'value': 'test_value22'} + + test_section1_expected = [test_option1_expected] + test_section2_expected = [test_option21_expected, test_option22_expected] + + # 1. set + # Test setting one option + self.cmd('config set test_section1.test_option1=test_value1' + args['flag']) + # Test setting multiple options + self.cmd('config set test_section2.test_option21=test_value21 test_section2.test_option22=test_value22' + args['flag']) + + # 2. get + # 2.1 Test get all sections + output = self.cmd('config get' + args['flag']).get_output_in_json() + self.assertListEqual(output['test_section1'], test_section1_expected) + self.assertListEqual(output['test_section2'], test_section2_expected) + + # 2.2 Test get one section + output = self.cmd('config get test_section1' + args['flag']).get_output_in_json() + self.assertListEqual(output, test_section1_expected) + output = self.cmd('config get test_section2' + args['flag']).get_output_in_json() + self.assertListEqual(output, test_section2_expected) + + # 2.3 Test get one item + output = self.cmd('config get test_section1.test_option1' + args['flag']).get_output_in_json() + self.assertDictEqual(output, test_option1_expected) + output = self.cmd('config get test_section2.test_option21' + args['flag']).get_output_in_json() + self.assertDictEqual(output, test_option21_expected) + output = self.cmd('config get test_section2.test_option22' + args['flag']).get_output_in_json() + self.assertDictEqual(output, test_option22_expected) + + with self.assertRaises(CLIError): + self.cmd('config get test_section1.test_option22' + args['flag']) + + # 3. unset + # Test unsetting one option + self.cmd('config unset test_section1.test_option1' + args['flag']) + # Test unsetting multiple options + self.cmd('config unset test_section2.test_option21 test_section2.test_option22' + args['flag']) + + os.chdir(original_path) + + +if __name__ == '__main__': + unittest.main() From cd0dc0f483249723787757cd27173e115b94d05f Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Tue, 21 Jul 2020 12:51:58 +0800 Subject: [PATCH 02/12] style --- doc/sphinx/azhelpgen/doc_source_map.json | 1 + .../cli/command_modules/config/_params.py | 1 - .../cli/command_modules/config/custom.py | 20 +++++++++---------- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/doc/sphinx/azhelpgen/doc_source_map.json b/doc/sphinx/azhelpgen/doc_source_map.json index 7d761b235c9..75f86e32522 100644 --- a/doc/sphinx/azhelpgen/doc_source_map.json +++ b/doc/sphinx/azhelpgen/doc_source_map.json @@ -1,5 +1,6 @@ { "az": "src/azure-cli/azure/cli/command_modules/profile/_help.py", + "confige": "src/azure-cli/azure/cli/command_modules/config/_help.py", "configure": "src/azure-cli/azure/cli/command_modules/configure/_help.py", "feedback": "src/azure-cli/azure/cli/command_modules/feedback/_help.py", "login": "src/azure-cli/azure/cli/command_modules/profile/_help.py", diff --git a/src/azure-cli/azure/cli/command_modules/config/_params.py b/src/azure-cli/azure/cli/command_modules/config/_params.py index cca706a22cc..9e2b32b5894 100644 --- a/src/azure-cli/azure/cli/command_modules/config/_params.py +++ b/src/azure-cli/azure/cli/command_modules/config/_params.py @@ -4,7 +4,6 @@ # -------------------------------------------------------------------------------------------- # pylint: disable=line-too-long -from azure.cli.core.commands.parameters import get_enum_type, get_three_state_flag def load_arguments(self, _): diff --git a/src/azure-cli/azure/cli/command_modules/config/custom.py b/src/azure-cli/azure/cli/command_modules/config/custom.py index 9c16a196cc5..bab3eb02b30 100644 --- a/src/azure-cli/azure/cli/command_modules/config/custom.py +++ b/src/azure-cli/azure/cli/command_modules/config/custom.py @@ -18,9 +18,7 @@ def _normalize_config_value(value): def config_set(cmd, key_value=None, local=False): - from azure.cli.core.cloud import cloud_forbid_telemetry, get_active_cloud_name if key_value: - defaults_section = cmd.cli_ctx.config.defaults_section_name with ScopedConfig(cmd.cli_ctx.config, local): for kv in key_value: # core.no_color=true @@ -67,12 +65,12 @@ def config_get(cmd, key=None, local=False): if not name: # Only section return items - else: - # section.option - try: - return next(x for x in items if x['name']==name) - except StopIteration: - raise CLIError("Configuration '{}' is not set.".format(key)) + + # section.option + try: + return next(x for x in items if x['name'] == name) + except StopIteration: + raise CLIError("Configuration '{}' is not set.".format(key)) def config_unset(cmd, key=None, local=False): @@ -82,9 +80,9 @@ def config_unset(cmd, key=None, local=False): if len(parts) == 1: raise CLIError("usage error: [section].[name]") - else: - section = parts[0] - name = parts[1] + + section = parts[0] + name = parts[1] with ScopedConfig(cmd.cli_ctx.config, local): cmd.cli_ctx.config.remove_option(section, name) From 920c262b29585af4a81e22661d69735995112ce1 Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Tue, 21 Jul 2020 13:29:43 +0800 Subject: [PATCH 03/12] Linter --- linter_exclusions.yml | 15 +++++++++++++++ .../azure/cli/command_modules/config/_help.py | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/linter_exclusions.yml b/linter_exclusions.yml index dc566e917cf..a8cd7be7bfc 100644 --- a/linter_exclusions.yml +++ b/linter_exclusions.yml @@ -89,6 +89,21 @@ cloud update: cloud_name: rule_exclusions: - no_parameter_defaults_for_update_commands +config set: + parameters: + key_value: + rule_exclusions: + - no_positional_parameters +config get: + parameters: + key: + rule_exclusions: + - no_positional_parameters +config unset: + parameters: + key: + rule_exclusions: + - no_positional_parameters cosmosdb collection create: parameters: db_resource_group_name: diff --git a/src/azure-cli/azure/cli/command_modules/config/_help.py b/src/azure-cli/azure/cli/command_modules/config/_help.py index 6d4181d1e56..b408959e55c 100644 --- a/src/azure-cli/azure/cli/command_modules/config/_help.py +++ b/src/azure-cli/azure/cli/command_modules/config/_help.py @@ -6,6 +6,11 @@ from knack.help_files import helps # pylint: disable=unused-import # pylint: disable=line-too-long, too-many-lines +helps['config'] = """ +type: group +short-summary: Manage Azure CLI configuration. +""" + helps['config set'] = """ type: command short-summary: Set a configuration. From 919a891412ab29620939d772b68ab18ecfd048f6 Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Tue, 21 Jul 2020 15:12:34 +0800 Subject: [PATCH 04/12] Install knack from src --- .azure-pipelines/templates/automation_test.yml | 2 ++ .azure-pipelines/templates/azdev_setup.yml | 3 +++ 2 files changed, 5 insertions(+) diff --git a/.azure-pipelines/templates/automation_test.yml b/.azure-pipelines/templates/automation_test.yml index cf00e46856b..aa9195fa35d 100644 --- a/.azure-pipelines/templates/automation_test.yml +++ b/.azure-pipelines/templates/automation_test.yml @@ -18,6 +18,8 @@ steps: azdev --version azdev setup -c ./ + # TODO: Remove this line once a new version of Knack is released with this change + pip install --force-reinstall git+https://github.com/jiasli/knack@config displayName: Setup Env - bash: | set -ev diff --git a/.azure-pipelines/templates/azdev_setup.yml b/.azure-pipelines/templates/azdev_setup.yml index 82298f2fe6c..86acba0b647 100644 --- a/.azure-pipelines/templates/azdev_setup.yml +++ b/.azure-pipelines/templates/azdev_setup.yml @@ -22,6 +22,9 @@ steps: else azdev setup -c $CLI_REPO_PATH -r $CLI_EXT_REPO_PATH fi + + # TODO: Remove this line once a new version of Knack is released with this change + pip install --force-reinstall git+https://github.com/jiasli/knack@config displayName: 'Azdev Setup' env: CLI_REPO_PATH: ${{ parameters.CLIRepoPath }} From cca1ba0b8f607d1d20934cc99fcabcd1d65b0e7c Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Tue, 21 Jul 2020 15:21:09 +0800 Subject: [PATCH 05/12] ci --- .azure-pipelines/templates/automation_test.yml | 2 +- .azure-pipelines/templates/azdev_setup.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines/templates/automation_test.yml b/.azure-pipelines/templates/automation_test.yml index aa9195fa35d..c1eac4d3cbf 100644 --- a/.azure-pipelines/templates/automation_test.yml +++ b/.azure-pipelines/templates/automation_test.yml @@ -18,7 +18,7 @@ steps: azdev --version azdev setup -c ./ - # TODO: Remove this line once a new version of Knack is released with this change + # TODO: Remove this line once a new version of Knack is released with this change pip install --force-reinstall git+https://github.com/jiasli/knack@config displayName: Setup Env - bash: | diff --git a/.azure-pipelines/templates/azdev_setup.yml b/.azure-pipelines/templates/azdev_setup.yml index 86acba0b647..2412cf22c73 100644 --- a/.azure-pipelines/templates/azdev_setup.yml +++ b/.azure-pipelines/templates/azdev_setup.yml @@ -23,7 +23,7 @@ steps: azdev setup -c $CLI_REPO_PATH -r $CLI_EXT_REPO_PATH fi - # TODO: Remove this line once a new version of Knack is released with this change + # TODO: Remove this line once a new version of Knack is released with this change pip install --force-reinstall git+https://github.com/jiasli/knack@config displayName: 'Azdev Setup' env: From 9793e224a63af585e581a20807d22074f3f4a63f Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Tue, 21 Jul 2020 16:00:29 +0800 Subject: [PATCH 06/12] Refine --- .../azure/cli/command_modules/config/_help.py | 6 +++--- .../cli/command_modules/config/_params.py | 18 +++++++++--------- .../config/tests/latest/test_config.py | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/config/_help.py b/src/azure-cli/azure/cli/command_modules/config/_help.py index b408959e55c..d111a49fffe 100644 --- a/src/azure-cli/azure/cli/command_modules/config/_help.py +++ b/src/azure-cli/azure/cli/command_modules/config/_help.py @@ -8,7 +8,7 @@ helps['config'] = """ type: group -short-summary: Manage Azure CLI configuration. +short-summary: Manage Azure CLI configuration. """ helps['config set'] = """ @@ -40,7 +40,7 @@ text: az config get - name: Get configurations in `core` section. text: az config get core - - name: Get configuration of key `core.no_color`. + - name: Get the configuration of key `core.no_color`. text: az config get core.no_color """ @@ -48,6 +48,6 @@ type: command short-summary: Unset a configuration. examples: - - name: Unset configuration of key `core.no_color`. + - name: Unset the configuration of key `core.no_color`. text: az config unset core.no_color """ diff --git a/src/azure-cli/azure/cli/command_modules/config/_params.py b/src/azure-cli/azure/cli/command_modules/config/_params.py index 9e2b32b5894..5ab9001d083 100644 --- a/src/azure-cli/azure/cli/command_modules/config/_params.py +++ b/src/azure-cli/azure/cli/command_modules/config/_params.py @@ -7,18 +7,18 @@ def load_arguments(self, _): + with self.argument_context('config') as c: + c.argument('local', action='store_true', help='Include the local configuration in addition to the global configuration.') - with self.argument_context('config set') as c: - c.positional('key_value', nargs='+', help="Space-separated configurations in the form of [section].[key]=[value].") - c.argument('local', action='store_true', help='Use the local config') c.ignore('_subscription') # ignore the global subscription param + with self.argument_context('config set') as c: + c.positional('key_value', nargs='+', help="Space-separated configurations in the form of
.=.") with self.argument_context('config get') as c: - c.positional('key', nargs='?', help='The configuration in the form of [section].[key]=[value].') - c.argument('local', action='store_true', help='Use the local config') - c.ignore('_subscription') # ignore the global subscription param + c.positional('key', nargs='?', help='The configuration to get. ' + 'If not provided, all sections and configurations will be listed. ' + 'If `section` is provided, all configurations under the specified section will be listed. ' + 'If `
.` is provided, only the corresponding configuration is shown.') with self.argument_context('config unset') as c: - c.positional('key', nargs='+', help='The configuration in the form of [section].[key]=[value].') - c.argument('local', action='store_true', help='Use the local config') - c.ignore('_subscription') # ignore the global subscription param + c.positional('key', nargs='+', help='The configuration to unset, in the form of
..') diff --git a/src/azure-cli/azure/cli/command_modules/config/tests/latest/test_config.py b/src/azure-cli/azure/cli/command_modules/config/tests/latest/test_config.py index b86290f8f71..e1fb7395d28 100644 --- a/src/azure-cli/azure/cli/command_modules/config/tests/latest/test_config.py +++ b/src/azure-cli/azure/cli/command_modules/config/tests/latest/test_config.py @@ -28,8 +28,8 @@ def test_config(self): os.chdir(tempdir) print("Using temp dir: {}".format(tempdir)) - global_test_args = {"source": os.path.expanduser('~\\.azure\\config'), "flag": ""} - local_test_args = {"source": os.path.join(tempdir, '.azure\\config'), "flag": " --local"} + global_test_args = {"source": os.path.expanduser(os.path.join('~', '.azure', 'config')), "flag": ""} + local_test_args = {"source": os.path.join(tempdir, '.azure', 'config'), "flag": " --local"} for args in (global_test_args, local_test_args): test_option1_expected = {'name': 'test_option1', 'source': args["source"], 'value': 'test_value1'} From ba13f996596497c632375691cb0d933659701fda Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Tue, 21 Jul 2020 16:26:47 +0800 Subject: [PATCH 07/12] Flake8 --- src/azure-cli-core/azure/cli/core/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/util.py b/src/azure-cli-core/azure/cli/core/util.py index bd9af35bc19..20839cc1386 100644 --- a/src/azure-cli-core/azure/cli/core/util.py +++ b/src/azure-cli-core/azure/cli/core/util.py @@ -882,7 +882,7 @@ def _log_response(response, **kwargs): return response -class ScopedConfig(object): +class ScopedConfig(): def __init__(self, cli_config, use_local_config=None): self.use_local_config = use_local_config From c686e44b59e3ec965c1872a5cadb859c1a0a1fbf Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Tue, 21 Jul 2020 16:53:40 +0800 Subject: [PATCH 08/12] Flake8 --- src/azure-cli-core/azure/cli/core/util.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/azure-cli-core/azure/cli/core/util.py b/src/azure-cli-core/azure/cli/core/util.py index 20839cc1386..2193a4972ec 100644 --- a/src/azure-cli-core/azure/cli/core/util.py +++ b/src/azure-cli-core/azure/cli/core/util.py @@ -882,7 +882,7 @@ def _log_response(response, **kwargs): return response -class ScopedConfig(): +class ScopedConfig: def __init__(self, cli_config, use_local_config=None): self.use_local_config = use_local_config From 9749ec04c6a9c3e0e4e918a079029c0fb66dab45 Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Wed, 22 Jul 2020 13:45:45 +0800 Subject: [PATCH 09/12] Temporarily fix CLI Automation Full Test --- scripts/ci/test_automation.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/scripts/ci/test_automation.sh b/scripts/ci/test_automation.sh index 080b3e118fc..dfeb78f0478 100755 --- a/scripts/ci/test_automation.sh +++ b/scripts/ci/test_automation.sh @@ -29,6 +29,9 @@ title 'Install private packages (optional)' title 'Install products' pip install -qqq $ALL_MODULES +# TODO: Remove this line once a new version of Knack is released with this change +pip install --force-reinstall git+https://github.com/jiasli/knack@config + title 'Installed packages' pip freeze From 803f2b67e666a512d03bc1e79665e39212714d6b Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Thu, 23 Jul 2020 15:43:59 +0800 Subject: [PATCH 10/12] Refine help --- .../azure/cli/command_modules/config/_help.py | 10 ++++++---- .../azure/cli/command_modules/config/_params.py | 10 ++++++++-- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/azure-cli/azure/cli/command_modules/config/_help.py b/src/azure-cli/azure/cli/command_modules/config/_help.py index d111a49fffe..ce17a912229 100644 --- a/src/azure-cli/azure/cli/command_modules/config/_help.py +++ b/src/azure-cli/azure/cli/command_modules/config/_help.py @@ -14,7 +14,9 @@ helps['config set'] = """ type: command short-summary: Set a configuration. -long-summary: For available configuration options, see https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration +long-summary: | + For available configuration options, see https://docs.microsoft.com/en-us/cli/azure/azure-cli-configuration. + By default without specifying --local, the configuration will be saved to `~/.azure/config`. examples: - name: Disable color with `core.no_color`. text: az config set core.no_color=true @@ -26,10 +28,10 @@ text: |- az config set logging.enable_log_file=true az config set logging.log_dir=~/az-logs - - name: Set the default resource group to `myRG`. - text: az config set default.group=myRG + - name: Set the default location to `westus2` and default resource group to `myRG`. + text: az config set defaults.location=westus2 defaults.group=MyResourceGroup - name: Set the default resource group to `myRG` on a local scope. - text: az config set default.group=myRG --local + text: az config set defaults.group=myRG --local """ helps['config get'] = """ diff --git a/src/azure-cli/azure/cli/command_modules/config/_params.py b/src/azure-cli/azure/cli/command_modules/config/_params.py index 5ab9001d083..9f35fca56a6 100644 --- a/src/azure-cli/azure/cli/command_modules/config/_params.py +++ b/src/azure-cli/azure/cli/command_modules/config/_params.py @@ -8,17 +8,23 @@ def load_arguments(self, _): with self.argument_context('config') as c: - c.argument('local', action='store_true', help='Include the local configuration in addition to the global configuration.') - c.ignore('_subscription') # ignore the global subscription param + with self.argument_context('config set') as c: c.positional('key_value', nargs='+', help="Space-separated configurations in the form of
.=.") + c.argument('local', action='store_true', help='Set as a local configuration in the working directory.') with self.argument_context('config get') as c: c.positional('key', nargs='?', help='The configuration to get. ' 'If not provided, all sections and configurations will be listed. ' 'If `section` is provided, all configurations under the specified section will be listed. ' 'If `
.` is provided, only the corresponding configuration is shown.') + c.argument('local', action='store_true', + help='Include local configuration. Scan from the working directory up to the root drive, then the global configuration ' + 'and return the first occurrence.') with self.argument_context('config unset') as c: c.positional('key', nargs='+', help='The configuration to unset, in the form of
..') + c.argument('local', action='store_true', + help='Include local configuration. Scan from the working directory up to the root drive, then the global configuration ' + 'and unset the first occurrence.') From 8b7c4c0430a86b52b3d5cf0e218574496beff1cb Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Mon, 27 Jul 2020 11:30:56 +0800 Subject: [PATCH 11/12] Update doc_source_map.json --- doc/sphinx/azhelpgen/doc_source_map.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/sphinx/azhelpgen/doc_source_map.json b/doc/sphinx/azhelpgen/doc_source_map.json index 75f86e32522..93aad4601e0 100644 --- a/doc/sphinx/azhelpgen/doc_source_map.json +++ b/doc/sphinx/azhelpgen/doc_source_map.json @@ -1,6 +1,6 @@ { "az": "src/azure-cli/azure/cli/command_modules/profile/_help.py", - "confige": "src/azure-cli/azure/cli/command_modules/config/_help.py", + "config": "src/azure-cli/azure/cli/command_modules/config/_help.py", "configure": "src/azure-cli/azure/cli/command_modules/configure/_help.py", "feedback": "src/azure-cli/azure/cli/command_modules/feedback/_help.py", "login": "src/azure-cli/azure/cli/command_modules/profile/_help.py", From 3b5eb409477cd92fb18c5d972c01384057ab278d Mon Sep 17 00:00:00 2001 From: Jiashuo Li Date: Mon, 27 Jul 2020 17:08:05 +0800 Subject: [PATCH 12/12] Use Knack 0.7.2 --- .azure-pipelines/templates/automation_test.yml | 3 --- .azure-pipelines/templates/azdev_setup.yml | 3 --- scripts/ci/test_automation.sh | 3 --- src/azure-cli-core/setup.py | 2 +- src/azure-cli/requirements.py3.Darwin.txt | 2 +- src/azure-cli/requirements.py3.Linux.txt | 2 +- src/azure-cli/requirements.py3.windows.txt | 2 +- 7 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.azure-pipelines/templates/automation_test.yml b/.azure-pipelines/templates/automation_test.yml index 197cac6e01b..76b8891b35c 100644 --- a/.azure-pipelines/templates/automation_test.yml +++ b/.azure-pipelines/templates/automation_test.yml @@ -13,9 +13,6 @@ steps: source env/bin/activate - # TODO: Remove this line once a new version of Knack is released with this change - pip install --force-reinstall git+https://github.com/jiasli/knack@config - if [[ "$(System.PullRequest.TargetBranch)" != "" ]]; then azdev test --series --repo=./ --src=HEAD --tgt=origin/$(System.PullRequest.TargetBranch) --cli-ci --profile ${{ parameters.profile }} else diff --git a/.azure-pipelines/templates/azdev_setup.yml b/.azure-pipelines/templates/azdev_setup.yml index cd33111a9d7..858a600524f 100644 --- a/.azure-pipelines/templates/azdev_setup.yml +++ b/.azure-pipelines/templates/azdev_setup.yml @@ -22,9 +22,6 @@ steps: else azdev setup -c $CLI_REPO_PATH -r $CLI_EXT_REPO_PATH fi - - # TODO: Remove this line once a new version of Knack is released with this change - pip install --force-reinstall git+https://github.com/jiasli/knack@config displayName: 'Azdev Setup' env: CLI_REPO_PATH: ${{ parameters.CLIRepoPath }} diff --git a/scripts/ci/test_automation.sh b/scripts/ci/test_automation.sh index dfeb78f0478..080b3e118fc 100755 --- a/scripts/ci/test_automation.sh +++ b/scripts/ci/test_automation.sh @@ -29,9 +29,6 @@ title 'Install private packages (optional)' title 'Install products' pip install -qqq $ALL_MODULES -# TODO: Remove this line once a new version of Knack is released with this change -pip install --force-reinstall git+https://github.com/jiasli/knack@config - title 'Installed packages' pip freeze diff --git a/src/azure-cli-core/setup.py b/src/azure-cli-core/setup.py index eb104a71e16..069656930bc 100644 --- a/src/azure-cli-core/setup.py +++ b/src/azure-cli-core/setup.py @@ -56,7 +56,7 @@ 'colorama~=0.4.1', 'humanfriendly>=4.7,<9.0', 'jmespath', - 'knack==0.7.1', + 'knack==0.7.2', 'msal~=1.0.0', 'msal-extensions~=0.1.3', 'msrest>=0.4.4', diff --git a/src/azure-cli/requirements.py3.Darwin.txt b/src/azure-cli/requirements.py3.Darwin.txt index 900bf69ba38..16ecb6e4489 100644 --- a/src/azure-cli/requirements.py3.Darwin.txt +++ b/src/azure-cli/requirements.py3.Darwin.txt @@ -99,7 +99,7 @@ isodate==0.6.0 Jinja2==2.10.1 jmespath==0.9.5 jsmin==2.2.2 -knack==0.7.1 +knack==0.7.2 MarkupSafe==1.1.1 mock==4.0.2 msrestazure==0.6.3 diff --git a/src/azure-cli/requirements.py3.Linux.txt b/src/azure-cli/requirements.py3.Linux.txt index ea3bf9bd2c4..05ec99498e2 100644 --- a/src/azure-cli/requirements.py3.Linux.txt +++ b/src/azure-cli/requirements.py3.Linux.txt @@ -99,7 +99,7 @@ isodate==0.6.0 Jinja2==2.10.1 jmespath==0.9.5 jsmin==2.2.2 -knack==0.7.1 +knack==0.7.2 MarkupSafe==1.1.1 mock==4.0.2 msrest==0.6.9 diff --git a/src/azure-cli/requirements.py3.windows.txt b/src/azure-cli/requirements.py3.windows.txt index 495e03dfa88..564f1a65515 100644 --- a/src/azure-cli/requirements.py3.windows.txt +++ b/src/azure-cli/requirements.py3.windows.txt @@ -97,7 +97,7 @@ isodate==0.6.0 Jinja2==2.10.1 jmespath==0.9.5 jsmin==2.2.2 -knack==0.7.1 +knack==0.7.2 MarkupSafe==1.1.1 mock==4.0.2 msrest==0.6.9