Add support for specifying --host via environment variable#4734
Add support for specifying --host via environment variable#4734MichaelEischer merged 2 commits intorestic:masterfrom
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. |
MichaelEischer
left a comment
There was a problem hiding this comment.
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
|
Thank you for taking care of the test. Very happy to see this coming through, it will be a great help. |
|
Hi. On the release BLOG [1], there is this line: Support for specifying hostname via environment variable RESTIC_HOST. It links to the env var docs, but the docs don't appear to mention RESTIC_HOST. thanks! [1] https://restic.net/blog/2024-07-26/restic-0.17.0-released/ |
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
--hostflag via theRESTIC_HOSTenvironment variable. This allows the user to set the hostname once and not have to specify it for every command. Commands that accept--hostbut do not work on snapshots (e.g.restic key ...) are not affected by this change. The--hostflag is still accepted and takes precedence over theRESTIC_HOSTenvironment variable.The changes are in
cmd_backup.gofor thebackupcommand andfind.gofor commands that use therestic.SnapshotFilteroptions.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).gofmton the code in all commits.