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

device: Add --json option for JSON output #2692

Merged
merged 1 commit into from
Nov 10, 2023

Conversation

bbugh
Copy link
Contributor

@bbugh bbugh commented Oct 27, 2023

Change-type: minor

Continuation of #2685 where we're using the CLI to automate targeting releases to certain devices based on the device tag, this adds --json to the device command, and includes device_tag.

@otaviojacobi
Copy link
Contributor

Hello @bbugh sorry for the delay on this, I am adding this to my to do list for this week. Can you please rebase and fix the docs conflict?

@bbugh
Copy link
Contributor Author

bbugh commented Nov 9, 2023

Fixed the docs conflict

Comment on lines +86 to +121
options.json
? {
$expand: {
device_tag: {
$select: ['tag_key', 'value'],
},
...expandForAppName.$expand,
},
}
: {
$select: [
'device_name',
'id',
'overall_status',
'is_online',
'ip_address',
'mac_address',
'last_connectivity_event',
'uuid',
'supervisor_version',
'is_web_accessible',
'note',
'os_version',
'memory_usage',
'memory_total',
'public_address',
'storage_block_device',
'storage_usage',
'storage_total',
'cpu_usage',
'cpu_temp',
'cpu_id',
'is_undervolted',
],
...expandForAppName,
},
Copy link
Member

Choose a reason for hiding this comment

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

Tiny suggestion so that the $select is still used when the --json flag is used.

Suggested change
options.json
? {
$expand: {
device_tag: {
$select: ['tag_key', 'value'],
},
...expandForAppName.$expand,
},
}
: {
$select: [
'device_name',
'id',
'overall_status',
'is_online',
'ip_address',
'mac_address',
'last_connectivity_event',
'uuid',
'supervisor_version',
'is_web_accessible',
'note',
'os_version',
'memory_usage',
'memory_total',
'public_address',
'storage_block_device',
'storage_usage',
'storage_total',
'cpu_usage',
'cpu_temp',
'cpu_id',
'is_undervolted',
],
...expandForAppName,
},
{
$select: [
'device_name',
'id',
'overall_status',
'is_online',
'ip_address',
'mac_address',
'last_connectivity_event',
'uuid',
'supervisor_version',
'is_web_accessible',
'note',
'os_version',
'memory_usage',
'memory_total',
'public_address',
'storage_block_device',
'storage_usage',
'storage_total',
'cpu_usage',
'cpu_temp',
'cpu_id',
'is_undervolted',
],
$expand: {
...expandForAppName.$expand,
...(options.json && {
device_tag: {
$select: ['tag_key', 'value'],
},
})
},
},

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively in case not including the $select was intentional, we could make clear that it was intentional by wrapping it in a ...(!options.json && { $select: [/*...*/] }), along w/ a comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@thgreasi thanks for the review.

It was intentional not to limit the json response based on the fields used by the table printer. JSON format in other tools is a raw data dump that allows the consumer to determine what data is important, which is one of the primary use cases for it. (See also similar discussion in my first PR).

I wouldn't personally add anything to the code because I think the intent of the code is clear based on the use case and experience, but I respect that it's y'all's codebase and I think you can commit that comment to it if you want.

Hope that helps.

@otaviojacobi otaviojacobi merged commit 8bfafe8 into balena-io:master Nov 10, 2023
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.

3 participants