diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 9af8c8a34ce..afcb2067e56 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -66,3 +66,4 @@ /src/azure-cli/azure/cli/command_modules/util/ @jiasli @zhoxing-ms @evelyn-ys /src/azure-cli/azure/cli/command_modules/vm/ @zhoxing-ms @jsntcy @wangzelin007 @yanzhudd @Drewm3 @TravisCragg-MSFT @nikhilpatel909 @sandeepraichura @hilaryw29 @GabstaMSFT @ramankumarlive @ushnaarshadkhan /src/azure-cli/azure/cli/command_modules/containerapp/ @zhoxing-ms @yanzhudd @ruslany @sanchitmehta @ebencarek @JennyLawrance @howang-ms @vinisoto @chinadragon0515 @vturecek @torosent @pagariyaalok @Juliehzl @jijohn14 @Greedygre @ShichaoQiu +/src/azure-cli/azure/cli/command_modules/daniel_module/ @DanielMicrosoft diff --git a/doc/sphinx/azhelpgen/doc_source_map.json b/doc/sphinx/azhelpgen/doc_source_map.json index 024469de003..5c15c78f6b0 100644 --- a/doc/sphinx/azhelpgen/doc_source_map.json +++ b/doc/sphinx/azhelpgen/doc_source_map.json @@ -77,5 +77,6 @@ "term": "src/azure-cli/azure/cli/command_modules/marketplaceordering/_help.py", "util": "src/azure-cli/azure/cli/command_modules/util/_help.py", "vm": "src/azure-cli/azure/cli/command_modules/vm/_help.py", - "vmss": "src/azure-cli/azure/cli/command_modules/vm/_help.py" + "vmss": "src/azure-cli/azure/cli/command_modules/vm/_help.py", + "daniel_module": "src/azure-cli/azure/cli/command_modules/daniel_module/_help.py" } \ No newline at end of file diff --git a/src/azure-cli/azure/cli/command_modules/daniel_module/__init__.py b/src/azure-cli/azure/cli/command_modules/daniel_module/__init__.py new file mode 100644 index 00000000000..4933ce04490 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/daniel_module/__init__.py @@ -0,0 +1,32 @@ +# -------------------------------------------------------------------------------------------- +# 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 + +from azure.cli.command_modules.daniel_module._help import helps # pylint: disable=unused-import + + +class Daniel_moduleCommandsLoader(AzCommandsLoader): + + def __init__(self, cli_ctx=None): + from azure.cli.core.commands import CliCommandType + from azure.cli.command_modules.daniel_module._client_factory import cf_daniel_module + daniel_module_custom = CliCommandType( + operations_tmpl='azure.cli.command_modules.daniel_module.custom#{}', + client_factory=cf_daniel_module) + super(Daniel_moduleCommandsLoader, self).__init__(cli_ctx=cli_ctx, + custom_command_type=daniel_module_custom) + + def load_command_table(self, args): + from azure.cli.command_modules.daniel_module.commands import load_command_table + load_command_table(self, args) + return self.command_table + + def load_arguments(self, command): + from azure.cli.command_modules.daniel_module._params import load_arguments + load_arguments(self, command) + + +COMMAND_LOADER_CLS = Daniel_moduleCommandsLoader diff --git a/src/azure-cli/azure/cli/command_modules/daniel_module/_client_factory.py b/src/azure-cli/azure/cli/command_modules/daniel_module/_client_factory.py new file mode 100644 index 00000000000..f1fabd29f59 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/daniel_module/_client_factory.py @@ -0,0 +1,12 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +def cf_daniel_module(cli_ctx, *_): + + from azure.cli.core.commands.client_factory import get_mgmt_service_client + # TODO: Replace CONTOSO with the appropriate label and uncomment + # from azure.mgmt.CONTOSO import CONTOSOManagementClient + # return get_mgmt_service_client(cli_ctx, CONTOSOManagementClient) + return None diff --git a/src/azure-cli/azure/cli/command_modules/daniel_module/_help.py b/src/azure-cli/azure/cli/command_modules/daniel_module/_help.py new file mode 100644 index 00000000000..aafb7f5fd63 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/daniel_module/_help.py @@ -0,0 +1,38 @@ +# coding=utf-8 +# -------------------------------------------------------------------------------------------- +# 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 + + +helps['daniel_module'] = """ + type: group + short-summary: Commands to manage Daniel_modules. +""" + +helps['daniel_module create'] = """ + type: command + short-summary: Create a Daniel_module. +""" + +helps['daniel_module list'] = """ + type: command + short-summary: List Daniel_modules. +""" + +# helps['daniel_module delete'] = """ +# type: command +# short-summary: Delete a Daniel_module. +# """ + +# helps['daniel_module show'] = """ +# type: command +# short-summary: Show details of a Daniel_module. +# """ + +# helps['daniel_module update'] = """ +# type: command +# short-summary: Update a Daniel_module. +# """ diff --git a/src/azure-cli/azure/cli/command_modules/daniel_module/_params.py b/src/azure-cli/azure/cli/command_modules/daniel_module/_params.py new file mode 100644 index 00000000000..2c479db0a5a --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/daniel_module/_params.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. +# -------------------------------------------------------------------------------------------- +# pylint: disable=line-too-long + +from knack.arguments import CLIArgumentType + + +def load_arguments(self, _): + + from azure.cli.core.commands.parameters import tags_type + from azure.cli.core.commands.validators import get_default_location_from_resource_group + + daniel_module_name_type = CLIArgumentType( + help='Name of the Daniel_module.', + id_part='name' + ) + + with self.argument_context('daniel_module') as c: + c.argument('tags', tags_type) + c.argument('location', validator=get_default_location_from_resource_group) + c.argument('daniel_module_name', daniel_module_name_type, options_list=['--name', '-n']) + + with self.argument_context('daniel_module list') as c: + c.argument('daniel_module_name', daniel_module_name_type, options_list=['--name', '-n']) diff --git a/src/azure-cli/azure/cli/command_modules/daniel_module/_validators.py b/src/azure-cli/azure/cli/command_modules/daniel_module/_validators.py new file mode 100644 index 00000000000..821630f5f34 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/daniel_module/_validators.py @@ -0,0 +1,20 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + + +def example_name_or_id_validator(cmd, namespace): + # Example of a storage account name or ID validator. + # See: https://github.com/Azure/azure-cli/blob/dev/doc/authoring_command_modules/authoring_commands.md#supporting-name-or-id-parameters + from azure.cli.core.commands.client_factory import get_subscription_id + from msrestazure.tools import is_valid_resource_id, resource_id + if namespace.storage_account: + if not is_valid_resource_id(namespace.RESOURCE): + namespace.storage_account = resource_id( + subscription=get_subscription_id(cmd.cli_ctx), + resource_group=namespace.resource_group_name, + namespace='Microsoft.Storage', + type='storageAccounts', + name=namespace.storage_account + ) diff --git a/src/azure-cli/azure/cli/command_modules/daniel_module/commands.py b/src/azure-cli/azure/cli/command_modules/daniel_module/commands.py new file mode 100644 index 00000000000..1233ba4ed36 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/daniel_module/commands.py @@ -0,0 +1,33 @@ +# -------------------------------------------------------------------------------------------- +# 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 import CliCommandType +from azure.cli.command_modules.daniel_module._client_factory import cf_daniel_module + + +def load_command_table(self, _): + + # TODO: Add command type here + # daniel_module_sdk = CliCommandType( + # operations_tmpl='.operations#.{}', + # client_factory=cf_daniel_module) + + + with self.command_group('daniel_module') as g: + g.custom_command('create', 'create_daniel_module') + # g.command('delete', 'delete') + g.custom_command('list', 'list_daniel_module') + # g.show_command('show', 'get') + # g.generic_update_command('update', setter_name='update', custom_func_name='update_daniel_module') + + + with self.command_group('daniel_module', is_preview=True): + pass + + +def create_daniel_module(cmd, client, name, location): + # Your create logic here + return f"Created {name} at {location}!" \ No newline at end of file diff --git a/src/azure-cli/azure/cli/command_modules/daniel_module/custom.py b/src/azure-cli/azure/cli/command_modules/daniel_module/custom.py new file mode 100644 index 00000000000..90490b67fe7 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/daniel_module/custom.py @@ -0,0 +1,27 @@ +# -------------------------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for license information. +# -------------------------------------------------------------------------------------------- + +from knack.util import CLIError + + +def create_daniel_module(cmd, daniel_module_name, location=None, tags=None): + # Simulate creation logic; normally you'd call SDK or service client here + result = { + 'name': daniel_module_name, + 'location': location, + 'tags': tags or {} + } + # Just returning the result dictionary as example + return result + + +def list_daniel_module(cmd, resource_group_name=None): + raise CLIError('TODO: Implement `daniel_module list`') + + +def update_daniel_module(cmd, instance, tags=None): + with cmd.update_context(instance) as c: + c.set_param('tags', tags) + return instance \ No newline at end of file diff --git a/src/azure-cli/azure/cli/command_modules/daniel_module/tests/__init__.py b/src/azure-cli/azure/cli/command_modules/daniel_module/tests/__init__.py new file mode 100644 index 00000000000..2dcf9bb68b3 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/daniel_module/tests/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- \ No newline at end of file diff --git a/src/azure-cli/azure/cli/command_modules/daniel_module/tests/latest/__init__.py b/src/azure-cli/azure/cli/command_modules/daniel_module/tests/latest/__init__.py new file mode 100644 index 00000000000..2dcf9bb68b3 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/daniel_module/tests/latest/__init__.py @@ -0,0 +1,5 @@ +# ----------------------------------------------------------------------------- +# Copyright (c) Microsoft Corporation. All rights reserved. +# Licensed under the MIT License. See License.txt in the project root for +# license information. +# ----------------------------------------------------------------------------- \ No newline at end of file diff --git a/src/azure-cli/azure/cli/command_modules/daniel_module/tests/latest/test_daniel_module_scenario.py b/src/azure-cli/azure/cli/command_modules/daniel_module/tests/latest/test_daniel_module_scenario.py new file mode 100644 index 00000000000..e0a344200e5 --- /dev/null +++ b/src/azure-cli/azure/cli/command_modules/daniel_module/tests/latest/test_daniel_module_scenario.py @@ -0,0 +1,40 @@ +# -------------------------------------------------------------------------------------------- +# 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 unittest + +from azure_devtools.scenario_tests import AllowLargeResponse +from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer) + + +TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..')) + + +class Daniel_moduleScenarioTest(ScenarioTest): + + @ResourceGroupPreparer(name_prefix='cli_test_daniel_module') + def test_daniel_module(self, resource_group): + + self.kwargs.update({ + 'name': 'test1' + }) + + self.cmd('daniel_module create -g {rg} -n {name} --tags foo=doo', checks=[ + self.check('tags.foo', 'doo'), + self.check('name', '{name}') + ]) + self.cmd('daniel_module update -g {rg} -n {name} --tags foo=boo', checks=[ + self.check('tags.foo', 'boo') + ]) + count = len(self.cmd('daniel_module list').get_output_in_json()) + self.cmd('daniel_module show - {rg} -n {name}', checks=[ + self.check('name', '{name}'), + self.check('resourceGroup', '{rg}'), + self.check('tags.foo', 'boo') + ]) + self.cmd('daniel_module delete -g {rg} -n {name}') + final_count = len(self.cmd('daniel_module list').get_output_in_json()) + self.assertTrue(final_count, count - 1) \ No newline at end of file