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

refactor: Create structs for each tools command to better isolate commands - cont'd #3340

Merged
merged 2 commits into from
Dec 18, 2024

Conversation

soltysh
Copy link
Contributor

@soltysh soltysh commented Dec 17, 2024

Description

Continuation of the effort to isolate commands. Followup to #3322.

This PR additionally changes how viper is initiated, see the first commit for that specifically.

Related Issue

Relates to #2773

Checklist before merging

@soltysh soltysh requested review from a team as code owners December 17, 2024 17:57
Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for zarf-docs ready!

Name Link
🔨 Latest commit bb80bbe
🔍 Latest deploy log https://app.netlify.com/sites/zarf-docs/deploys/6762a3a2b2bc740008eb8e11
😎 Deploy Preview https://deploy-preview-3340--zarf-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

codecov bot commented Dec 17, 2024

@soltysh
Copy link
Contributor Author

soltysh commented Dec 17, 2024

@AustinAbro321 ptal

Copy link
Contributor

@AustinAbro321 AustinAbro321 left a comment

Choose a reason for hiding this comment

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

one small comment then looks good

// Flags for using an external Git server
cmd.Flags().StringVar(&updateCredsInitOpts.GitServer.Address, "git-url", v.GetString(common.VInitGitURL), lang.CmdInitFlagGitURL)
cmd.Flags().StringVar(&updateCredsInitOpts.GitServer.PushUsername, "git-push-username", v.GetString(common.VInitGitPushUser), lang.CmdInitFlagGitPushUser)
cmd.Flags().StringVar(&updateCredsInitOpts.GitServer.PushPassword, "git-push-password", v.GetString(common.VInitGitPushPass), lang.CmdInitFlagGitPushPass)
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like this is getting set to a default value as seen in the markdown changes. IMO we should avoid setting the default here, a user might run zarf tools update-creds --registry-username="user" --registry-password="password" and have their git creds updated to the default unexpectedly.

This changed because previously v.GetString(common.VInitGitPushUser) was given a default after this command was loaded, but now tools is loaded last. We don't want to remove v.GetString(common.VInitGitPushUser) from this line since a user may set init.git.push_username in their config.toml file. Instead we could move rootCmd.AddCommand(tools.NewToolsCommand()) to be first in NewZarfCommand().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I've noticed that change, but I didn't dig too deep into where it came from. I'll check if the order you're talking about has an effect. Honestly, I'd prefer to rewrite it such that the order shouldn't matter.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want to remove v.GetString(common.VInitGitPushUser) from this line since a user may set init.git.push_username in their config.toml file. Instead we could move rootCmd.AddCommand(tools.NewToolsCommand()) to be first in NewZarfCommand().

Sounds like we should consider defaulting and config values, and how these interact. I think once I reach the point where I will want to decouple config values and flags it might get addressed.

Before this change we have two separate methods, one for initializing
Viper - InitViper, and another to retrieve it - GetViper. This may lead
to either Viper not being initiated, thus leading to nil pointer
dereference error or initializing more than once.

After this change, we will ensure Viper is initialized only once.

Signed-off-by: Maciej Szulik <[email protected]>
@soltysh soltysh added this pull request to the merge queue Dec 18, 2024
Merged via the queue into zarf-dev:main with commit ead7577 Dec 18, 2024
26 checks passed
@soltysh soltysh deleted the tools_cmds branch December 18, 2024 15:23
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