Skip to content

Commit

Permalink
Convert extension example to knack (#5093)
Browse files Browse the repository at this point in the history
  • Loading branch information
derekbekoe authored Dec 13, 2017
1 parent 39cd532 commit d314bd4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

from azure.cli.core.help_files import helps
from knack.help_files import helps

from azure.cli.core import AzCommandsLoader

helps['hello world'] = """
type: command
Expand All @@ -13,9 +15,21 @@
def helloworld():
print('Hello World.')

def load_params(_):
pass

def load_commands():
from azure.cli.core.commands import cli_command
cli_command(__name__, 'hello world', 'azext_myexampleextension#helloworld')
class HelloWorldCommandsLoader(AzCommandsLoader):

def __init__(self, cli_ctx=None):
from azure.cli.core.commands import CliCommandType
custom_type = CliCommandType(operations_tmpl='azext_myexampleextension#{}')
super(HelloWorldCommandsLoader, self).__init__(cli_ctx=cli_ctx,
custom_command_type=custom_type)

def load_command_table(self, args):
with self.command_group('hello') as g:
g.custom_command('world', 'helloworld')
return self.command_table

def load_arguments(self, _):
pass

COMMAND_LOADER_CLS = HelloWorldCommandsLoader
2 changes: 1 addition & 1 deletion src/azure-cli-core/azure/cli/core/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def _load_command_loader(loader, args, name, prefix):
# else:
loader.cmd_to_loader_map[cmd] = [command_loader]
else:
logger.debug("Command module '%s' is missing `COMMAND_LOADER_CLS` entry.", name)
logger.debug("Module '%s' is missing `COMMAND_LOADER_CLS` entry.", name)
return command_table


Expand Down

0 comments on commit d314bd4

Please sign in to comment.