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 --yaml output option #52

Merged
merged 2 commits into from
Mar 8, 2024
Merged

Add --yaml output option #52

merged 2 commits into from
Mar 8, 2024

Conversation

rustydb
Copy link
Contributor

@rustydb rustydb commented Mar 5, 2024

Summary and Scope

Issue Type

  • RFE Pull Request

Adds a --yaml output option to output valid, parseable YAML.

Even though the default output looks like YAML, it isn't, and shouldn't be used with YAML parsers.

Default output:

[681]rusty@HPE-XHD22YD7DW:~/gitstuffs/cray-shasta/gru> ./gru --insecure show system 10.100.254.79 | yq
Asynchronously querying [    1] hosts ...
Error: bad file '-': yaml: line 2: found character that cannot start any token
[682]rusty@HPE-XHD22YD7DW:~/gitstuffs/cray-shasta/gru> ./gru --insecure show system surtur-ncn-m001-mgmt.hpc.amslabs.hpecorp.net | yq
Asynchronously querying [    1] hosts ...
Error: bad file '-': yaml: line 2: found character that cannot start any token

With YAML flags, yq has no problem parsing the output:

[679]rusty@HPE-XHD22YD7DW:~/gitstuffs/cray-shasta/gru> ./gru --insecure show system 10.100.254.79 --yaml | yq
Asynchronously querying [    1] hosts ...
10.100.254.79:
  bios_version: A43 v1.38 (10/30/2020)
  firmware_version: iLO 5 v2.44
  processor_model: 'AMD EPYC 7302P 16-Core Processor               '
  manufacturer: HPE
  model: ProLiant DL325 Gen10 Plus
[687]rusty@HPE-XHD22YD7DW:~/gitstuffs/cray-shasta/gru> ./gru --insecure show system surtur-ncn-m001-mgmt.hpc.amslabs.hpecorp.net --yaml | yq
Asynchronously querying [    1] hosts ...
surtur-ncn-m001-mgmt.hpc.amslabs.hpecorp.net:
  bios_version: A43 v1.38 (10/30/2020)
  firmware_version: iLO 5 v2.44
  processor_model: 'AMD EPYC 7302P 16-Core Processor               '
  manufacturer: HPE
  model: ProLiant DL325 Gen10 Plus

Risks and Mitigations

@rustydb rustydb requested a review from a team as a code owner March 5, 2024 18:02
@rustydb rustydb requested review from muresan, heemstra, manderson-hpe, jpdavis-prof and jacobsalmela and removed request for heemstra March 5, 2024 18:02
@rustydb
Copy link
Contributor Author

rustydb commented Mar 5, 2024

I'll add more tests once #53 merges.

Now that these messages print to `os.Stderr`, we do not need to
conditionally print them.

The conditional print was implemented to avoid breaking the JSON output
with non-JSON, but since it's going to `os.Stderr` now it doesn't
matter.

This opens the way for adding other output formats without needing to
maintain these conditionals.
@rustydb rustydb force-pushed the 50-yaml branch 3 times, most recently from f00c3d8 to 11f4ce1 Compare March 5, 2024 22:46
Even though the default output looks similar to YAML, it is not
marshalled as YAML and thus shouldn't be parsed by YAML parsers since it
is unsafe.

This adds an official YAML output option, which also updates several
keys to match YAML naming conventions (snake case).
@rustydb rustydb merged commit 1bb33d3 into main Mar 8, 2024
3 checks passed
@rustydb rustydb deleted the 50-yaml branch March 8, 2024 17:40
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.

Add an output option for YAML
2 participants