-
Notifications
You must be signed in to change notification settings - Fork 143
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
Conversation
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? |
Fixed the docs conflict |
15c0005
to
c7b13c6
Compare
change-type: minor
c7b13c6
to
d78045b
Compare
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, | ||
}, |
There was a problem hiding this comment.
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.
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'], | |
}, | |
}) | |
}, | |
}, |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 thedevice
command, and includesdevice_tag
.