Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

cmd: factor FlagName into fs.Option #2541

Nick Craig-Woode7e467fb3a34
diff --git a/cmd/cmd.go b/cmd/cmd.go
index 43f69f6d3..8bbd1cf95 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -447,10 +447,7 @@ func AddBackendFlags() {
}
done[opt.Name] = struct{}{}
// Make a flag from each option
- name := strings.Replace(opt.Name, "_", "-", -1) // convert snake_case to kebab-case
- if !opt.NoPrefix {
- name = fsInfo.Prefix + "-" + name
- }
+ name := opt.FlagName(fsInfo.Prefix)
found := pflag.CommandLine.Lookup(name) != nil
if !found {
// Take first line of help only
diff --git a/fs/fs.go b/fs/fs.go
index 66e2c02b0..390d9364a 100644
--- a/fs/fs.go
+++ b/fs/fs.go
@@ -154,6 +154,20 @@ func (o *Option) Type() string {
return reflect.TypeOf(o.value()).Name()
}
+// FlagName for the option
+func (o *Option) FlagName(prefix string) string {
+ name := strings.Replace(o.Name, "_", "-", -1) // convert snake_case to kebab-case
+ if !o.NoPrefix {
+ name = prefix + "-" + name
+ }
+ return name
+}
+
+// EnvVarName for the option
+func (o *Option) EnvVarName(prefix string) string {
+ return OptionToEnv(prefix + "-" + o.Name)
+}
+
// OptionExamples is a slice of examples
type OptionExamples []OptionExample