Skip to content

Provide json output of console command plugin:list #20744

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

Merged

Conversation

ziegenberg
Copy link
Contributor

Description:

Add a new option --json to the console command plugin:list and output the information as json instead of a rendered table. This helps with automation when managing Matomo installs.

Review

@michalkleiner michalkleiner self-assigned this May 18, 2023
@michalkleiner
Copy link
Contributor

Hi @ziegenberg,
thank you for opening the pull-request, that's a good idea to support the JSON format.

I wonder though whether we should provide the same data in both the tabular and JSON output, mainly now thinking about the comment field in the JSON output. That is not consistent with what the user sees in the table. Can we keep the same behaviour as in the table view where it's all within the Status field, and keep the labels in the same style, i.e. plugin/core/status/version?

What do you think about that?

I will also suggest a few minor code-style tweaks that you can bulk-commit directly from Github's interface.

@michalkleiner michalkleiner changed the title provide json output of console command plugin:list Provide json output of console command plugin:list May 18, 2023
@michalkleiner michalkleiner removed their assignment May 19, 2023
@ziegenberg
Copy link
Contributor Author

Hi @michalkleiner,

I incorporated the proposed style changes (is there an automatic style checker I missed?).

Regarding the differences in tabular and JSON output: On the one side I didn't want to change the table headers for the tabular output and on the other side Core or optional? isn't a good key for a JSON field, so I opted for simple keys for the JSON output (plugin, core, activated, version) which describe the data most accurately. I also used boolean data fields, cause they are easy to use with automation tools and the JSON output will most likely be used with such tools. I, for example, want to use the new JSON output to make life with Ansible Automation and my Matomo Ansible role easier. Mixing error information with data in fields is rather a handicap in this regard, so I opted for the comment field.

If you like, I can extend the description of the new --json option and the description of the plugin:list command to further explain the data output and the meaning of the columns and respectively the fields.

@michalkleiner
Copy link
Contributor

Thanks @ziegenberg, you didn't miss a checker, we are slowly implementing CS changes and in the end there will be one.
Regarding the JSON format and the differences to the tabular output, I take your point and reasoning. I provided my feedback with the view that it can be addressed either at the generation point or when processing the JSON output at the other end, but I agree that for automated and/or scripted processing boolean values are easier to work with than deciphering the values from the text output, so all good on that part.

With that, I'm happy to approve this, I'd ask @sgiehl for his opinion and then we might be able to merge that in.

@michalkleiner michalkleiner requested a review from sgiehl May 19, 2023 11:31
@michalkleiner
Copy link
Contributor

One point I'd make is that in the long-term, we might want to add a --json switch to other commands that produce tabular output and there it would be basically about the output format, but the data would be the same, which is why I also inclined towards having the data the same.
Alternatively, we could update the tabular view of the plugin:list output to have the same boolean columns and the comment column. I'd be open to that. What do you think about that, @sgiehl?

@sgiehl
Copy link
Member

sgiehl commented May 19, 2023

Personally I wouldn't see it as part of a console command to support different return types at all. That is what our API is meant for and is able to handle automatically. So if something is needed in different formats, I would suggest to add an API method for that instead.

@ziegenberg
Copy link
Contributor Author

Aside from the changes discussed above, I pulled up the static function wrapInTag from \Piwik\Plugins\CoreAdminHome\Commands\ConfigGet and respectively \Piwik\Plugins\CoreAdminHome\Commands\ConfigSet to Piwik\Plugin\ConsoleCommand to make it available to other Commands as well. I found several places in other commands where wrapInTag could be used. Are you interested in another PR?

@ziegenberg
Copy link
Contributor Author

Having low-level access to certain information makes automation very easy and convenient. The console command eg. already provides config:get and it has a --format option, which formats the output as json, yaml or text; the default is json.

@ziegenberg ziegenberg force-pushed the console-command-list-plugins-json-output branch from f34ec50 to fd811db Compare May 19, 2023 12:21
@ziegenberg
Copy link
Contributor Author

I rebased onto the current 5.x-dev

@ziegenberg ziegenberg force-pushed the console-command-list-plugins-json-output branch from fd811db to 0aa81ca Compare May 19, 2023 13:54
@github-actions

This comment was marked as outdated.

@github-actions github-actions bot added the Stale The label used by the Close Stale Issues action label Jun 3, 2023
Add a new option `--json` to the console command plugin:list and output
the information as json instead of a rendered table. This helps with
automation when managing Matomo installs.

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
…ake it available to other Commands

Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
Signed-off-by: Daniel Ziegenberg <daniel@ziegenberg.at>
@sgiehl sgiehl force-pushed the console-command-list-plugins-json-output branch from 0aa81ca to 5a5e3e4 Compare June 5, 2023 08:04
Copy link
Member

@sgiehl sgiehl left a comment

Choose a reason for hiding this comment

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

Thanks @ziegenberg for the contribution.
The changes in this PR are looking fine to me.
I'll merge this one. We can have further thoughts if moving that to API might make more sense later as well.

@sgiehl sgiehl added this to the 5.0.0 milestone Jun 5, 2023
@sgiehl sgiehl added Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. and removed Stale The label used by the Close Stale Issues action labels Jun 5, 2023
@sgiehl sgiehl merged commit a721722 into matomo-org:5.x-dev Jun 5, 2023
@ziegenberg ziegenberg deleted the console-command-list-plugins-json-output branch June 6, 2023 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc.
Development

Successfully merging this pull request may close these issues.

3 participants