Skip to content

Conversation

@jiasli
Copy link
Member

@jiasli jiasli commented Jul 21, 2020

Description

Resolve #13981

Add new config command module. This PR relies on Knack change microsoft/knack#217.

Testing Guide

Set

Disable color with core.no_color.

az config set core.no_color=true

Hide warnings and only show errors with core.only_show_errors.

az config set core.only_show_errors=true

Turn on client-side telemetry.

az config set core.collect_telemetry=true

Turn on file logging and set its location.

az config set logging.enable_log_file=true
az config set logging.log_dir=~/az-logs

Set the default resource group to myRG.

az config set default.group=myRG

Set the default resource group to myRG on a local scope.

az config set default.group=myRG --local

Get

Get all configurations.

az config get

Get configurations in core section.

az config get core

Get configuration of key core.no_color.

az config get core.no_color

Unset

Unset configurations of key core.no_color.

az config unset core.no_color

@yonzhan yonzhan added this to the S173 milestone Jul 21, 2020
@yonzhan
Copy link
Collaborator

yonzhan commented Jul 21, 2020

Config refactor

@@ -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",
Copy link
Member

Choose a reason for hiding this comment

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

extra e?

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh! Nice catch. Perhaps our CI should check it? @haroldrandom @myronfanqiu

@jiasli jiasli marked this pull request as ready for review July 27, 2020 03:30
try:
return next(x for x in items if x['name'] == name)
except StopIteration:
raise CLIError("Configuration '{}' is not set.".format(key))
Copy link
Contributor

Choose a reason for hiding this comment

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

Another option for this case is to return empty string. Personally, I prefer empty string for this case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Empty string means the config is actually set to '', which is different from the concept of "not set".

Copy link
Contributor

Choose a reason for hiding this comment

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

Make sense to me. Maybe we should also confirm this with PM.

name = parts[1]

with ScopedConfig(cmd.cli_ctx.config, local):
cmd.cli_ctx.config.remove_option(section, name)
Copy link
Contributor

Choose a reason for hiding this comment

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

What will be returned if key is not set?

Copy link
Member Author

@jiasli jiasli Jul 27, 2020

Choose a reason for hiding this comment

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

It will ignore the operation and return False. See remove_option:

remove_option(section, option)
Remove the specified option from the specified section. If the section does not exist, raise NoSectionError. If the option existed to be removed, return True; otherwise return False.

Copy link
Member Author

Choose a reason for hiding this comment

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

However, configparser.NoSectionError is ignored by Knack.

https://github.com/microsoft/knack/blob/148173e6fd02bd721920e6b33c9f508b4d584ae9/knack/config.py#L219-L223

            try:
                existed = self.config_parser.remove_option(section, option)
                self.set(self.config_parser)
            except configparser.NoSectionError:
                pass

We'd better confirm with PM about the behavior later.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agree with your suggestion.

@jiasli jiasli requested a review from arrownj July 28, 2020 02:46
Copy link
Contributor

@mmyyrroonn mmyyrroonn left a comment

Choose a reason for hiding this comment

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

Approved for linter_exclusions.yml file

@jiasli jiasli merged commit dd24e80 into Azure:dev Jul 28, 2020
@jiasli jiasli deleted the config branch July 28, 2020 03:06
@jiasli
Copy link
Member Author

jiasli commented Apr 19, 2023

An excerpt from the design spec https://github.com/jiasli/azure-cli-spec/blob/master/az-config.md:

Additional work - migrate to settings.json

settings.json is the latest unwritten convention of Microsoft open source project, like Visual Studio Code and Windows Terminal.

Visual Studio Code

The config file is at C:\Users\xxx\AppData\Roaming\Code\User\settings.json:

{
    "terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
    "terminal.integrated.scrollback": 99999,
    "editor.minimap.enabled": false,
    ...
}

Windows Terminal

The config file is at C:\Users\xxx\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json:

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "defaultProfile": "{574e775e-4f2a-5b96-ac1e-a2962a402336}",

    "profiles":
    [
        {
            // Make changes here to the powershell.exe profile
            "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
            "name": "Windows PowerShell",
            "commandline": "powershell.exe",
            "hidden": false
        },
        ...
    ],
    ...
}

Using settings.json will open up more possibilities like "hover" help (controlled by editor.hover.enabled in VSCode) using the "$schema" property:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Configure] A more versatile az configure

6 participants