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

feat: introduce output format flag for zarf tools get-creds and zarf package list #3415

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

AustinAbro321
Copy link
Contributor

@AustinAbro321 AustinAbro321 commented Jan 21, 2025

Description

Introduces the --output-flag for zarf tools get-creds and zarf package list. Additionally deprecates the --output flag on zarf version to be --output-format. There are other commands that print tables in the future such as zarf connect list and zarf dev lint. get-creds and list were chosen because the output of these commands is more likely to be used in automation.

Related Issue

Relates to #3224

Checklist before merging

Copy link

netlify bot commented Jan 21, 2025

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit ab19d4f
🔍 Latest deploy log https://app.netlify.com/sites/zarf-docs/deploys/6793e8b67dc5060008c36e3f

src/cmd/tools/zarf.go Fixed Show fixed Hide fixed
Copy link

codecov bot commented Jan 21, 2025

Codecov Report

Attention: Patch coverage is 56.54450% with 83 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/cmd/zarf_tools.go 64.00% 33 Missing and 3 partials ⚠️
src/cmd/package.go 45.09% 25 Missing and 3 partials ⚠️
src/cmd/root.go 18.18% 9 Missing ⚠️
src/cmd/version.go 62.50% 6 Missing ⚠️
src/cmd/viper.go 69.23% 2 Missing and 2 partials ⚠️
Files with missing lines Coverage Δ
src/pkg/message/credentials.go 0.00% <ø> (ø)
src/cmd/viper.go 59.72% <69.23%> (+59.72%) ⬆️
src/cmd/version.go 29.72% <62.50%> (+29.72%) ⬆️
src/cmd/root.go 25.59% <18.18%> (+25.59%) ⬆️
src/cmd/package.go 41.58% <45.09%> (+41.58%) ⬆️
src/cmd/zarf_tools.go 35.98% <64.00%> (+35.98%) ⬆️

... and 28 files with indirect coverage changes

src/cmd/zarf_tools.go Fixed Show fixed Hide fixed
if logFile != nil {
logFile.Pause()
defer logFile.Resume()
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this was not ported over, but logFile is only used with the legacy logger, and since this now goes to stdout it doesn't go to the logfile anyway

@AustinAbro321 AustinAbro321 marked this pull request as ready for review January 24, 2025 14:53
@AustinAbro321 AustinAbro321 requested review from a team as code owners January 24, 2025 14:53
mkcp
mkcp previously approved these changes Jan 24, 2025
Copy link
Contributor

@mkcp mkcp left a comment

Choose a reason for hiding this comment

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

Small nit and notes for future improvements. will reapprove

return err
}
fmt.Fprint(o.outputWriter, string(output))
case "table":
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a blocker, but the table rendering can be done in a reusable way with reflection. One example

func newVersionOptions() *versionOptions {
return &versionOptions{
outputFormat: "",
// TODO accept output writer as a parameter to the root Zarf command and pass it through here
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

cmd.Flags().StringVarP(&o.outputFormat, "output", "o", "", "Output format (yaml|json)")
cmd.Flags().VarP(&o.outputFormat, "output-format", "o", "Output format (yaml|json)")
cmd.Flags().VarP(&o.outputFormat, "output", "", "Output format (yaml|json)")
cmd.Flags().MarkDeprecated("output", "output is deprecated. Please use --output-format instead")
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

GetCredsKey string `json:"getCredsKey"`
}

// TODO Zarf state should be changed to have empty values when a service is not in use
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

src/cmd/zarf_tools.go Outdated Show resolved Hide resolved
return err
}
fmt.Fprint(out, string(output))
case outputTable:
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking, but similar comment to above, this can be solved in a reusable way with reflection for table headers.

Signed-off-by: Austin Abro <[email protected]>
Copy link
Contributor

@mkcp mkcp left a comment

Choose a reason for hiding this comment

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

LGTM

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