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: add --config flag, an alternative to ZARF_CONFIG env var #2328

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

Conversation

waveywaves
Copy link
Contributor

Description

add --config flag, an alternative to ZARF_CONFIG env var

Related Issue

Fixes #2178

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Other (security config, docs update, etc)

Checklist before merging

Copy link

netlify bot commented Feb 22, 2024

Deploy Preview for zarf-docs ready!

Name Link
🔨 Latest commit 5452ec6
🔍 Latest deploy log https://app.netlify.com/sites/zarf-docs/deploys/668ff87a529f1800089f2948
😎 Deploy Preview https://deploy-preview-2328--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.

@waveywaves waveywaves marked this pull request as ready for review March 5, 2024 13:04
src/cmd/root.go Outdated Show resolved Hide resolved
src/test/e2e/30_config_file_test.go Outdated Show resolved Hide resolved
src/cmd/common/setup.go Outdated Show resolved Hide resolved
@AustinAbro321
Copy link
Contributor

Hey @waveywaves sorry for the delay but I would like to get this merged in at some point, I think it's pretty close. Could you merge main into this branch? There are a lot of conflicts but they're all from the new docs site so merging in main and running make docs-and-schema should fix it.

Also could you add the following line to the appropriate block in src/cmd/internal.go

addHiddenDummyFlag(toolCmd, "config-path")

@waveywaves waveywaves requested review from dgershman and a team as code owners July 2, 2024 20:20
@waveywaves waveywaves force-pushed the en/2178 branch 2 times, most recently from 5a57bd4 to 1e5f744 Compare July 2, 2024 22:29
Comment on lines +127 to +137
if !argsConfigPathIsPresent() {
if cfgFile != "" {
// Use config file from the flag.
v.SetConfigFile(cfgFile)
} else {
// Search config paths in the current directory and $HOME/.zarf.
v.AddConfigPath(".")
v.AddConfigPath("$HOME/.zarf")
v.SetConfigName("zarf-config")
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

A lot of this block is duplicated directly under this

Comment on lines +175 to +180
func SetViperConfigFilePath(vcfgFilePath string) {
if vcfgFilePath != "" {
v.SetConfigFile(config.CommonOptions.ConfigPath)
vConfigError = v.ReadInConfig()
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO it would be more clear to inline this function

@@ -570,7 +571,7 @@ $ zarf tools update-creds \
--artifact-push-username={USERNAME} --artifact-push-token={PASSWORD}

# NOTE: Any credentials omitted from flags without a service key specified will be autogenerated - URLs will only change if specified.
# Config options can also be set with the 'init' section of a Zarf config file.
# ConfigPath options can also be set with the 'init' section of a Zarf config file.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# ConfigPath options can also be set with the 'init' section of a Zarf config file.

Let's just delete this comment, it seems that the config it's referring to is not the init file.


e2e.CleanFiles(path)

// Test the config file flag
os.Unsetenv("ZARF_CONFIG")
Copy link
Contributor

@AustinAbro321 AustinAbro321 Jul 11, 2024

Choose a reason for hiding this comment

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

This was originally necessary but can now be deleted. While it won't break anything, each test should not expect environment variables to have been set by other tests.

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.

Thank you for getting back to this, it is a great feature to have

@@ -38,15 +44,17 @@ func TestConfigFile(t *testing.T) {
e2e.CleanFiles(path)
}

func configFileTests(t *testing.T, dir, path string) {
func configFileTests(t *testing.T, dir, path string, configPath string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

A bit of a nit, but I think it would be simpler if the function signature was

func configFileTests(t *testing.T, dir, path string, extraArgs ...string)

Then it could be called like below

configFileTests(t, dir, path, "--config-path", configPath)

and the args could simply be appended like this

args := append([]string{"package", "create", dir, "--confirm"}, extraArgs...)

@AustinAbro321 AustinAbro321 changed the title add --config flag, an alternative to ZARF_CONFIG env var feat: add --config flag, an alternative to ZARF_CONFIG env var Jul 11, 2024
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.

alternative zarf config path as a CLI option
2 participants