1
mirror of https://github.com/rclone/rclone synced 2024-12-01 10:31:57 +01:00

cmd: factor FlagName into fs.Option #2541

This commit is contained in:
Nick Craig-Wood 2018-09-24 21:27:30 +01:00
parent 5fde7d8b12
commit e7e467fb3a
2 changed files with 15 additions and 4 deletions

View File

@ -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

View File

@ -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