{Core} Add util function highlight_command#16349
Conversation
| """highlight a command to make it colored. | ||
|
|
There was a problem hiding this comment.
Some example can be very helpful, like
azure-cli/src/azure-cli-core/azure/cli/core/util.py
Lines 1186 to 1190 in 903ecf1
There was a problem hiding this comment.
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.
Can you add comment about the rule used?
There was a problem hiding this comment.
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.
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
There was a problem hiding this comment.
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 <jiasli@microsoft.com>
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.