-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 support for specifying --host via environment variable #4734
Add support for specifying --host via environment variable #4734
Conversation
I have a question to the maintainers -- where and/or how would you suggest putting the proper tests for this feature? Most of the tests related to this area seem to circumvent option processing, so I can't find a good example to follow. I am a (relative) beginner to golang. |
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.
Thanks for the PR! I only have a few comments, see below.
The best way for testing is probably to use something like the following. That simply creates a new flagSet, configures it, then parses a test string and verifies the outcome:
set := pflag.NewFlagSet("test", pflag.PanicOnError)
flt := &restic.SnapshotFilter{}
initMultiSnapshotFilter(set, flt, false)
err := set.Parse([]string{"--host", "abc"})
rtest.OK(t, err)
// assert on flt.Hosts
This commit adds support for specifying the `--host` option via the `RESTIC_HOST` environment variable. This is done by extending option processing in `cmd_backup.go` and for `restic.SnapshotFilter` in `find.go`.
ded8f67
to
6af086f
Compare
6af086f
to
347e9d0
Compare
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.
LGTM. I've applied my suggestions and added a short test.
Thank you for taking care of the test. Very happy to see this coming through, it will be a great help. |
What does this PR change? What problem does it solve?
This PR adds the ability to set the hostname for most commands that accept the
--host
flag via theRESTIC_HOST
environment variable. This allows the user to set the hostname once and not have to specify it for every command. Commands that accept--host
but do not work on snapshots (e.g.restic key ...
) are not affected by this change. The--host
flag is still accepted and takes precedence over theRESTIC_HOST
environment variable.The changes are in
cmd_backup.go
for thebackup
command andfind.go
for commands that use therestic.SnapshotFilter
options.Was the change previously discussed in an issue or on the forum?
Closees #4733
Checklist
changelog/unreleased/
that describes the changes for our users (see template).gofmt
on the code in all commits.