-
Notifications
You must be signed in to change notification settings - Fork 3.3k
[Core] Linter rule for service_name.json #17428
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
01dde9f
[Core] Linter rule for service_name.json
qwordy 5b292a4
Fix a small bug
qwordy 8051af4
afd
qwordy 1cafd2a
interactive
qwordy b120e7e
bicep
qwordy 89d16d2
comment
qwordy bc3f510
Merge branch 'dev' of https://github.com/Azure/azure-cli into linter
qwordy 3ef41a5
remove description and extensionname
qwordy c2ed3e9
update
qwordy 4910fcd
update
qwordy bd01fa7
message
qwordy a19ffbd
Merge branch 'dev' of https://github.com/Azure/azure-cli into linter
qwordy ea80fc9
update
qwordy cad0e3e
style
qwordy 3a1cf43
Merge branch 'dev' of https://github.com/Azure/azure-cli into linter
qwordy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| #!/usr/bin/env python | ||
|
|
||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
| """ | ||
| Check format of service_name.json. Command and AzureServiceName are required. Others are optional. | ||
| Each highest level command group should have reference in service_name.json. | ||
| """ | ||
| import json | ||
|
|
||
| from azure.cli.core import MainCommandsLoader, AzCli | ||
| from azure.cli.core._help import AzCliHelp | ||
| from azure.cli.core.commands import AzCliCommandInvoker | ||
| from azure.cli.core.file_util import create_invoker_and_load_cmds_and_args, get_all_help | ||
| from azure.cli.core.parser import AzCliCommandParser | ||
|
|
||
|
|
||
| def main(): | ||
| az_cli = AzCli(cli_name='az', | ||
| commands_loader_cls=MainCommandsLoader, | ||
| invocation_cls=AzCliCommandInvoker, | ||
| parser_cls=AzCliCommandParser, | ||
| help_cls=AzCliHelp) | ||
| create_invoker_and_load_cmds_and_args(az_cli) | ||
| help_files = get_all_help(az_cli) | ||
| high_command_set = set() | ||
| for help_file in help_files: | ||
| if help_file.command: | ||
| high_command_set.add(help_file.command.split()[0]) | ||
| print('high_command_set:') | ||
| print(high_command_set) | ||
|
|
||
| # Load and check service_name.json | ||
| with open('src/azure-cli/service_name.json') as f: | ||
| service_names = json.load(f) | ||
| print('Verifying src/azure-cli/service_name.json') | ||
| service_name_map = {} | ||
| for service_name in service_names: | ||
| command = service_name['Command'] | ||
| service = service_name['AzureServiceName'] | ||
| if not command.startswith('az '): | ||
| raise Exception('{} does not start with az!'.format(command)) | ||
| if not service: | ||
| raise Exception('AzureServiceName of {} is empty!'.format(command)) | ||
| service_name_map[command[3:]] = service | ||
| print('service_name_map:') | ||
| print(service_name_map) | ||
|
|
||
| # Check existence in service_name.json | ||
| for high_command in high_command_set: | ||
| if high_command not in service_name_map: | ||
| raise Exception('No entry of {} in service_name.json. Please add one to the file.'.format(high_command)) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.