mirror of
https://github.com/rclone/rclone.git
synced 2024-11-23 02:01:25 +08:00
cmd: factor FlagName into fs.Option #2541
This commit is contained in:
parent
5fde7d8b12
commit
e7e467fb3a
|
@ -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
|
||||
|
|
14
fs/fs.go
14
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
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user