Skip to content
Merged
Changes from 5 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
8b75491
Add v0 hook to AzCliCommandParser class.
christopher-o-toole Apr 6, 2020
c701c75
Add None check to _get_failure_recovery_arguments.
christopher-o-toole Apr 6, 2020
f4a3b04
Make _make_failure_recovery_recommendations a class method to appease…
christopher-o-toole Apr 6, 2020
bfc47b1
Make 2 spaces before inline comment.
christopher-o-toole Apr 6, 2020
1cbc45c
Make extension parsing more robust. Use telemetry data when available.
christopher-o-toole Apr 7, 2020
12b4993
Incorporate suggestions from PR. Document failure recovery argument f…
christopher-o-toole Apr 8, 2020
9758cdc
Correct typo in comment. Fix CLI inline comment style issues.
christopher-o-toole Apr 8, 2020
8e81255
Make suggestion message a class variable, use inspect for logging sta…
christopher-o-toole Apr 13, 2020
21b246a
Fix _get_failure_recovery_recommendation return value, reduce length …
christopher-o-toole Apr 13, 2020
eca1ebf
Consolidated instance attributes. Add draft of failure recovery hook …
christopher-o-toole Apr 13, 2020
91aeab5
Adjust whitespace in test_parser
christopher-o-toole Apr 13, 2020
74ec310
Improve readability and style through addition of ExpectedParameters …
christopher-o-toole Apr 13, 2020
356f111
Update src/azure-cli-core/azure/cli/core/parser.py
christopher-o-toole Apr 14, 2020
098fc5f
Update src/azure-cli-core/azure/cli/core/parser.py
christopher-o-toole Apr 14, 2020
d45addf
Update src/azure-cli-core/azure/cli/core/parser.py
christopher-o-toole Apr 14, 2020
08737bf
Apply suggested changes. Simplify logging.
christopher-o-toole Apr 14, 2020
dd36ac3
Merge branch 'thoth-extension-hook' of https://github.com/christopher…
christopher-o-toole Apr 14, 2020
a9191aa
Correct typo in comment. Default parameters variable to empty list.
christopher-o-toole Apr 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/azure-cli-core/azure/cli/core/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ def _get_completions(self, comp_words, cword_prefix, cword_prequote, last_wordbr
class AzCliCommandParser(CLICommandParser):
"""ArgumentParser implementation specialized for the Azure CLI utility."""

@staticmethod
def recommendation_provider(version, command, parameters, extension):
pass

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed there are many cases where recommendation can be triggered, please list all of these cases in the PR description. Including how to trigger them.

Use logger.debug to log the args and make sure they are provided as expected.

We can schedule a meeting to further discuss this design.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will put a more detailed description of some of the most common cases where recommendations are triggered soon.

I'd like to schedule a meeting with you if you have time. I'll contact you on Teams for details.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added better logging through logger.debug.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added table of different command failures. Will add additional details sometime tonight.


def __init__(self, cli_ctx=None, cli_help=None, **kwargs):
self.command_source = kwargs.pop('_command_source', None)
self.subparser_map = {}
Expand Down Expand Up @@ -141,6 +145,7 @@ def error(self, message):
with CommandLoggerContext(logger):
logger.error('%(prog)s: error: %(message)s', args)
self.print_usage(sys.stderr)
self._make_failure_recovery_recommendations(*self._get_failure_recovery_arguments())
Comment thread
christopher-o-toole marked this conversation as resolved.
Outdated
self.exit(2)

def format_help(self):
Expand All @@ -165,6 +170,40 @@ def enable_autocomplete(self):
argcomplete.autocomplete(self, validator=lambda c, p: c.lower().startswith(p.lower()),
default_completer=lambda _: ())

@classmethod
def _make_failure_recovery_recommendations(cls, *args, **kwargs):
if telemetry.is_telemetry_enabled():
cls.recommendation_provider(telemetry._get_core_version(), *args, **kwargs) # pylint: disable=protected-access
Comment thread
christopher-o-toole marked this conversation as resolved.
Outdated

def _get_failure_recovery_arguments(self, action=None):
command = self.prog[3:].strip()
Comment thread
jiasli marked this conversation as resolved.
parameters = self.cli_ctx.data['safe_params'] if self.cli_ctx and self.cli_ctx.data else None
Comment thread
christopher-o-toole marked this conversation as resolved.
Outdated
extension = None

session = telemetry._session # pylint: disable=protected-access
Comment thread
christopher-o-toole marked this conversation as resolved.
Outdated

if not command and session.raw_command:
command = session.raw_command
if not parameters and session.parameters:
try:
command = ','.join(session.parameters)
except Exception: # pylint: disable=broad-except
pass

if action and action.dest == '_subcommand':
for _, context in action.choices.items():
if isinstance(context.command_source, ExtensionCommandSource):
extension = context.command_source.extension_name
elif isinstance(self.subparser_map, dict):
for _, context in self.subparser_map.items():
if isinstance(context.command_source, ExtensionCommandSource):
extension = context.command_source.extension_name
else:
extension = None
break

return (command, parameters, extension)
Comment thread
christopher-o-toole marked this conversation as resolved.
Outdated

def _get_values(self, action, arg_strings):
value = super(AzCliCommandParser, self)._get_values(action, arg_strings)
if action.dest and isinstance(action.dest, str) and not action.dest.startswith('_'):
Expand Down Expand Up @@ -202,4 +241,5 @@ def _check_value(self, action, value):
suggestion_msg += '\n'.join(['\t' + candidate for candidate in candidates])
print(suggestion_msg, file=sys.stderr)

self._make_failure_recovery_recommendations(*self._get_failure_recovery_arguments(action))
Comment thread
christopher-o-toole marked this conversation as resolved.
Outdated
self.exit(2)