Skip to content
Prev Previous commit
Next Next commit
Working version of new example replacement
  • Loading branch information
mirdaki-ms committed Mar 2, 2020
commit a1b71b1d3167107c9afaadf7c727a00d75dfd889
11 changes: 11 additions & 0 deletions src/azure-cli-core/azure/cli/core/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ def __init__(self, cli_ctx):
group_help_cls=CliGroupHelpFile,
help_cls=CliHelpFile)
from knack.help import HelpObject
# Used to specify what the original help request was for
self.original_nouns = ''

# TODO: This workaround is used to avoid a bizarre bug in Python 2.7. It
# essentially reassigns Knack's HelpObject._normalize_text implementation
Expand All @@ -150,6 +152,7 @@ def new_normalize_text(s):
# override
def show_help(self, cli_name, nouns, parser, is_group):
self.update_loaders_with_help_file_contents(nouns)
self.original_nouns = ' '.join(nouns)
super(AzCliHelp, self).show_help(cli_name, nouns, parser, is_group)
print(SURVEY_PROMPT)

Expand Down Expand Up @@ -195,6 +198,10 @@ def update_loaders_with_help_file_contents(self, nouns):
def example_provider(help_file):
return help_file.examples

@staticmethod
def replace_examples(examples, command):
return examples


class CliHelpFile(KnackHelpFile):

Expand Down Expand Up @@ -248,6 +255,10 @@ def load(self, options):
for loader in ordered_loaders:
loader.versioned_load(self, options)

# Used as a hook for changing the default examples
if self.help_ctx.original_nouns == self.command:
self.examples = AzCliHelp.replace_examples(self.examples, self.command)


class CliGroupHelpFile(KnackGroupHelpFile, CliHelpFile):

Expand Down