Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add raw_result to CommandResultItem #235

Merged
merged 1 commit into from
Mar 25, 2021
Merged

Conversation

jiasli
Copy link
Member

@jiasli jiasli commented Mar 2, 2021

Add raw_result to CommandResultItem, so that the raw result (before query) can be used by post-output hint (Azure/azure-cli#16242).

@@ -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.

Base automatically changed from master to dev March 12, 2021 07:02
Copy link
Contributor

@evelyn-ys evelyn-ys left a comment

Choose a reason for hiding this comment

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

Ok with me if breaking change is acceptable😆

@jiasli jiasli merged commit 03b46ab into microsoft:dev Mar 25, 2021
@jiasli jiasli deleted the raw-result branch March 25, 2021 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants