Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion knack/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def invoke(self, args, initial_invocation_data=None, out_file=None):
if cmd_result and cmd_result.result is not None:
formatter = self.output.get_formatter(output_type)
self.output.out(cmd_result, formatter=formatter, out_file=out_file)
self.raise_event(EVENT_CLI_SUCCESSFUL_EXECUTE, result=cmd_result.result)
self.raise_event(EVENT_CLI_SUCCESSFUL_EXECUTE, result=cmd_result)
Copy link
Member Author

Choose a reason for hiding this comment

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

Send the full CommandResultItem in case post-output hint relies on other attributes:

knack/knack/util.py

Lines 23 to 32 in 587abe5

class CommandResultItem(object): # pylint: disable=too-few-public-methods
def __init__(self, result, table_transformer=None, is_query_active=False,
exit_code=0, error=None, raw_result=None):
self.result = result
self.error = error
self.exit_code = exit_code
self.table_transformer = table_transformer
self.is_query_active = is_query_active
# The result before applying query
self.raw_result = raw_result

Copy link
Contributor

@evelyn-ys evelyn-ys Mar 25, 2021

Choose a reason for hiding this comment

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

Can we add another parameter into EVENT_CLI_SUCCESSFUL_EXECUTE to keep cmd_result instead of overwrite the value of result?

Although azure-cli didn't use EVENT_CLI_SUCCESSFUL_EXECUTE event now, but I'm afraid some other cli depend on knack might face breaking change in result type. Since event handler func usually use func(*arg, **kwargs) so adding new paremeter won't cause breaking change.

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding arg in function invocation may also trigger breaking change if the callee doesn't accept the new arg.

We never guaranteed there will be no breaking changes:

https://github.com/microsoft/knack

The project is in initial development phase. We recommend pinning to at least a specific minor version when marking knack as a dependency in your project.

except KeyboardInterrupt as ex:
exit_code = 1
self.result = CommandResultItem(None, error=ex, exit_code=exit_code)
Expand Down
3 changes: 2 additions & 1 deletion knack/invocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,4 +230,5 @@ def execute(self, args):
return CommandResultItem(event_data['result'],
exit_code=0,
table_transformer=cmd_tbl[parsed_args.command].table_transformer,
is_query_active=self.data['query_active'])
is_query_active=self.data['query_active'],
raw_result=cmd_result)
4 changes: 3 additions & 1 deletion knack/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@

class CommandResultItem(object): # pylint: disable=too-few-public-methods
def __init__(self, result, table_transformer=None, is_query_active=False,
exit_code=0, error=None):
exit_code=0, error=None, raw_result=None):
self.result = result
self.error = error
self.exit_code = exit_code
self.table_transformer = table_transformer
self.is_query_active = is_query_active
# The result before applying query
self.raw_result = raw_result


class CLIError(Exception):
Expand Down