-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} Add util function highlight_command #16349
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
Conversation
| """highlight a command to make it colored. | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some example can be very helpful, like
azure-cli/src/azure-cli-core/azure/cli/core/util.py
Lines 1186 to 1190 in 903ecf1
| def resource_to_scopes(resource): | |
| """Convert the ADAL resource ID to MSAL scopes by appending the /.default suffix and return a list. | |
| For example: | |
| 'https://management.core.windows.net/' -> ['https://management.core.windows.net//.default'] | |
| 'https://managedhsm.azure.com' -> ['https://managedhsm.azure.com/.default'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added more comments about the highlighting rules. The return type is of list of styled text, not easy to provide example.
| if arg.startswith('-') and '=' not in arg: | ||
| style = Style.ACTION | ||
| argument_begins = True | ||
| elif not argument_begins and '=' not in arg: | ||
| style = Style.ACTION |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add comment about the rule used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I made some comments at #16257 (comment)
The logic of = handling is for commands with positional argument. However, it works for az config set a=b, but it doesn't work for az config unset output. It is the nature of positional argument that we can NOT decide whether an arg (like output) is
- part of a command, or
- a positional argument
until semantic analysis is involved.
Let's keep it simple and treat it as part of the command by now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another possible solution is to utilize linter_exclusions.yml which contains the full list of commands with positional arguments:
azure-cli/linter_exclusions.yml
Lines 1181 to 1185 in 2c52cbc
| config set: | |
| parameters: | |
| key_value: | |
| rule_exclusions: | |
| - no_positional_parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good proposal, but also would make the function much more complex and harder to maintain.
I prefer we keep it simple for now, until we really need to consider the case.
Co-authored-by: Jiashuo Li <[email protected]>
Description
This PR adds an util function to highlight a command.
The function may be used in
Testing Guide
History Notes
[Component Name 1] BREAKING CHANGE: az command a: Make some customer-facing breaking change.
[Component Name 2] az command b: Add some customer-facing feature.
This checklist is used to make sure that common guidelines for a pull request are followed.
The PR title and description has followed the guideline in Submitting Pull Requests.
I adhere to the Command Guidelines.
I adhere to the Error Handling Guidelines.