Skip to content
This repository has been archived by the owner on Jul 14, 2023. It is now read-only.

Commit

Permalink
fix wait help info (#344)
Browse files Browse the repository at this point in the history
  • Loading branch information
qiaozha authored Apr 28, 2020
1 parent 1120e41 commit a2ebdba
Show file tree
Hide file tree
Showing 13 changed files with 119 additions and 29 deletions.
42 changes: 41 additions & 1 deletion src/plugins/azgenerator/TemplateAzureCliHelp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import { HeaderGenerator } from "./Header";
import { ToMultiLine, ToJsonString } from "../../utils/helper"

const maxShortSummary = 119

let showExampleStr = "";
let allSupportWaited = ['create', 'update', 'delete'];
export function GenerateAzureCliHelp(model: CodeModelAz): string[] {
let header: HeaderGenerator = new HeaderGenerator();
header.disableTooManyLines = true;
Expand All @@ -27,6 +28,8 @@ export function GenerateAzureCliHelp(model: CodeModelAz): string[] {
//let methods: string[] = model.CommandGroup_Commands;

let allSubGroup: Map<string, boolean> = new Map<string, boolean>();
let hasWait = false;
let allLongRunCommand = [];
if (model.SelectFirstCommand()) {
do {

Expand All @@ -35,6 +38,18 @@ export function GenerateAzureCliHelp(model: CodeModelAz): string[] {
allSubGroup.set(subCommandGroupName, true);
output = output.concat(generateCommandGroupHelp(model, subCommandGroupName));
}
if(model.Command_IsLongRun) {
hasWait = true;
let waitParam = "";
if (allSupportWaited.indexOf(model.Command_MethodName) < 0) {
waitParam = "create";
} else {
waitParam = model.Command_MethodName;
}
if(allLongRunCommand.indexOf(waitParam + "d") < 0) {
allLongRunCommand.push(waitParam + "d");
}
}
let commandOutput: string [] = generateCommandHelp(model);
//output.push("before output.length: " + output.length);
output = output.concat(commandOutput);
Expand All @@ -45,6 +60,9 @@ export function GenerateAzureCliHelp(model: CodeModelAz): string[] {
}
}
while (model.SelectNextCommand());
if (hasWait) {
output = output.concat(generateWaitCommandHelp(model.CommandGroup_Name, allLongRunCommand));
}
}
} while (model.SelectNextCommandGroup());;

Expand All @@ -58,6 +76,25 @@ export function GenerateAzureCliHelp(model: CodeModelAz): string[] {
return header.getLines().concat(output);
}

function generateWaitCommandHelp(commandGroup, allLongRunCommand) {
let output = [];
output.push("");
output.push("helps['" + commandGroup + " wait'] = \"\"\"");
output.push(" type: command");
let summary = " short-summary: Place the CLI in a waiting state until a condition of the " + commandGroup + " is met.";
ToMultiLine(summary, output, 119, true);
output.push(" examples:");
for(let waitParam of allLongRunCommand) {
let name = " - name: Pause executing next line of CLI script until the " + commandGroup + " is successfully " + waitParam + ".";
ToMultiLine(name, output, 119, true);
output.push(" text: |-");
let line = showExampleStr.replace(/ show /g, ' wait ') + " --" + waitParam;
ToMultiLine(line, output, 119, true);
}
output.push("\"\"\"");
return output;
}

function generateCommandGroupHelp(model: CodeModelAz, subCommandGroupName = "") {
let output = [];
output.push("");
Expand Down Expand Up @@ -124,6 +161,9 @@ function generateCommandHelp(model: CodeModelAz, needUpdate: boolean = false) {
output.push(" - name: " + example.Title);
output.push(" text: |-");
let line = " " + parameters.join(' ');
if (model.Command_MethodName == 'show') {
showExampleStr = line;
}
ToMultiLine(line, output, 119, true);
}

Expand Down
7 changes: 7 additions & 0 deletions src/test/scenarios/datafactory/configuration/readme.python.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ Please also specify `--python-sdks-folder=<path to the root directory of your az
Use `--python-mode=update` if you already have a setup.py and just want to update the code itself.

``` yaml $(python)
directive:
- from: swagger-document
where: $.info
transform: >
$.title = 'DFAZManagementClient';
$.description = 'The DFAZ Client.';
return $;
python:
azure-arm: true
license-header: MICROSOFT_MIT_NO_VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
from azext_datafactory.generated._help import helps # pylint: disable=unused-import


class DataFactoryManagementClientCommandsLoader(AzCommandsLoader):
class DFAZManagementClientCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
from azext_datafactory.generated._client_factory import cf_datafactory
datafactory_custom = CliCommandType(
operations_tmpl='azext_datafactory.custom#{}',
client_factory=cf_datafactory)
super(DataFactoryManagementClientCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=datafactory_custom)
super(DFAZManagementClientCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=datafactory_custom)

def load_command_table(self, args):
from azext_datafactory.generated.commands import load_command_table
Expand All @@ -43,4 +43,4 @@ def load_arguments(self, command):
pass


COMMAND_LOADER_CLS = DataFactoryManagementClientCommandsLoader
COMMAND_LOADER_CLS = DFAZManagementClientCommandsLoader
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

def cf_datafactory(cli_ctx, *_):
from azure.cli.core.commands.client_factory import get_mgmt_service_client
from ..vendored_sdks.datafactory import DataFactoryManagementClient
return get_mgmt_service_client(cli_ctx, DataFactoryManagementClient)
from ..vendored_sdks.datafactory import DFAZManagementClient
return get_mgmt_service_client(cli_ctx, DFAZManagementClient)


def cf_factory(cli_ctx, *_):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def call_scenario(test, rg):


@try_manual
class DataFactoryManagementClientScenarioTest(ScenarioTest):
class DFAZManagementClientScenarioTest(ScenarioTest):

@ResourceGroupPreparer(name_prefix='clitestdatafactory_exampleResourceGroup'[:7], key='rg', parameter_name='rg')
def test_datafactory(self, rg):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._data_factory_management_client import DataFactoryManagementClient
from ._dfaz_management_client import DFAZManagementClient
from ._version import VERSION

__version__ = VERSION
__all__ = ['DataFactoryManagementClient']
__all__ = ['DFAZManagementClient']

try:
from ._patch import patch_sdk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
from azure.core.credentials import TokenCredential


class DataFactoryManagementClientConfiguration(Configuration):
"""Configuration for DataFactoryManagementClient.
class DFAZManagementClientConfiguration(Configuration):
"""Configuration for DFAZManagementClient.
Note that all parameters used to create this instance are saved as instance
attributes.
Expand All @@ -43,7 +43,7 @@ def __init__(
raise ValueError("Parameter 'credential' must not be None.")
if subscription_id is None:
raise ValueError("Parameter 'subscription_id' must not be None.")
super(DataFactoryManagementClientConfiguration, self).__init__(**kwargs)
super(DFAZManagementClientConfiguration, self).__init__(**kwargs)

self.credential = credential
self.subscription_id = subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
# pylint: disable=unused-import,ungrouped-imports
from typing import Any, Optional

from ._configuration import DataFactoryManagementClientConfiguration
from ._configuration import DFAZManagementClientConfiguration
from .operations import FactoryOperations
from . import models


class DataFactoryManagementClient(object):
"""DataFactoryManagementClient.
class DFAZManagementClient(object):
"""The DFAZ Client.
:ivar factory: FactoryOperations operations
:vartype factory: azure.mgmt.datafactory.operations.FactoryOperations
Expand All @@ -43,7 +43,7 @@ def __init__(
# type: (...) -> None
if not base_url:
base_url = 'https://management.azure.com'
self._config = DataFactoryManagementClientConfiguration(credential, subscription_id, **kwargs)
self._config = DFAZManagementClientConfiguration(credential, subscription_id, **kwargs)
self._client = ARMPipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
Expand All @@ -58,7 +58,7 @@ def close(self):
self._client.close()

def __enter__(self):
# type: () -> DataFactoryManagementClient
# type: () -> DFAZManagementClient
self._client.__enter__()
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from ._data_factory_management_client_async import DataFactoryManagementClient
__all__ = ['DataFactoryManagementClient']
from ._dfaz_management_client_async import DFAZManagementClient
__all__ = ['DFAZManagementClient']
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
from azure.core.credentials import TokenCredential


class DataFactoryManagementClientConfiguration(Configuration):
"""Configuration for DataFactoryManagementClient.
class DFAZManagementClientConfiguration(Configuration):
"""Configuration for DFAZManagementClient.
Note that all parameters used to create this instance are saved as instance
attributes.
Expand All @@ -40,7 +40,7 @@ def __init__(
raise ValueError("Parameter 'credential' must not be None.")
if subscription_id is None:
raise ValueError("Parameter 'subscription_id' must not be None.")
super(DataFactoryManagementClientConfiguration, self).__init__(**kwargs)
super(DFAZManagementClientConfiguration, self).__init__(**kwargs)

self.credential = credential
self.subscription_id = subscription_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
from azure.mgmt.core import AsyncARMPipelineClient
from msrest import Deserializer, Serializer

from ._configuration_async import DataFactoryManagementClientConfiguration
from ._configuration_async import DFAZManagementClientConfiguration
from .operations_async import FactoryOperations
from .. import models


class DataFactoryManagementClient(object):
"""DataFactoryManagementClient.
class DFAZManagementClient(object):
"""The DFAZ Client.
:ivar factory: FactoryOperations operations
:vartype factory: azure.mgmt.datafactory.aio.operations_async.FactoryOperations
Expand All @@ -38,7 +38,7 @@ def __init__(
) -> None:
if not base_url:
base_url = 'https://management.azure.com'
self._config = DataFactoryManagementClientConfiguration(credential, subscription_id, **kwargs)
self._config = DFAZManagementClientConfiguration(credential, subscription_id, **kwargs)
self._client = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs)

client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
Expand All @@ -51,7 +51,7 @@ def __init__(
async def close(self) -> None:
await self._client.close()

async def __aenter__(self) -> "DataFactoryManagementClient":
async def __aenter__(self) -> "DFAZManagementClient":
await self._client.__aenter__()
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
setup(
name='datafactory',
version=VERSION,
description='Microsoft Azure Command-Line Tools DataFactoryManagementClient Extension',
description='Microsoft Azure Command-Line Tools DFAZManagementClient Extension',
author='Microsoft Corporation',
author_email='azpycli@microsoft.com',
url='https://github.com/Azure/azure-cli-extensions/tree/master/src/datafactory',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@
az managed-network mn delete --name "myManagedNetwork" --resource-group "myResourceGroup"
"""

helps['managed-network mn wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of the managed-network mn is met.
examples:
- name: Pause executing next line of CLI script until the managed-network mn is successfully updated.
text: |-
az managed-network mn wait --name "myManagedNetwork" --resource-group "myResourceGroup" --updated
- name: Pause executing next line of CLI script until the managed-network mn is successfully deleted.
text: |-
az managed-network mn wait --name "myManagedNetwork" --resource-group "myResourceGroup" --deleted
"""

helps['managed-network mn scope-assignment'] = """
type: group
short-summary: managed-network mn scope-assignment
Expand Down Expand Up @@ -194,6 +206,20 @@
edNetwork" --resource-group "myResourceGroup"
"""

helps['managed-network mn group wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of the managed-network mn group is met.
examples:
- name: Pause executing next line of CLI script until the managed-network mn group is successfully created.
text: |-
az managed-network mn group wait --group-name "myManagedNetworkGroup1" --managed-network-name "myManaged\
Network" --resource-group "myResourceGroup" --created
- name: Pause executing next line of CLI script until the managed-network mn group is successfully deleted.
text: |-
az managed-network mn group wait --group-name "myManagedNetworkGroup1" --managed-network-name "myManaged\
Network" --resource-group "myResourceGroup" --deleted
"""

helps['managed-network managed-network-peering-policy'] = """
type: group
short-summary: managed-network managed-network-peering-policy
Expand Down Expand Up @@ -293,3 +319,20 @@
az managed-network managed-network-peering-policy delete --managed-network-name "myManagedNetwork" --pol\
icy-name "myHubAndSpoke" --resource-group "myResourceGroup"
"""

helps['managed-network managed-network-peering-policy wait'] = """
type: command
short-summary: Place the CLI in a waiting state until a condition of the managed-network managed-network-peering-po\
licy is met.
examples:
- name: Pause executing next line of CLI script until the managed-network managed-network-peering-policy is succe\
ssfully created.
text: |-
az managed-network managed-network-peering-policy wait --managed-network-name "myManagedNetwork" --polic\
y-name "myHubAndSpoke" --resource-group "myResourceGroup" --created
- name: Pause executing next line of CLI script until the managed-network managed-network-peering-policy is succe\
ssfully deleted.
text: |-
az managed-network managed-network-peering-policy wait --managed-network-name "myManagedNetwork" --polic\
y-name "myHubAndSpoke" --resource-group "myResourceGroup" --deleted
"""

0 comments on commit a2ebdba

Please sign in to comment.