mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 09:41:44 +08:00
Add ability for FS to have a Config helper function run
This commit is contained in:
parent
1ea9972be7
commit
1b3a49929b
23
fs/config.go
23
fs/config.go
|
@ -150,6 +150,11 @@ func Command(commands []string) byte {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Asks the user for Yes or No and returns true or false
|
||||||
|
func Confirm() bool {
|
||||||
|
return Command([]string{"yYes", "nNo"}) == 'y'
|
||||||
|
}
|
||||||
|
|
||||||
// Choose one of the defaults or type a new string if newOk is set
|
// Choose one of the defaults or type a new string if newOk is set
|
||||||
func Choose(what string, defaults, help []string, newOk bool) string {
|
func Choose(what string, defaults, help []string, newOk bool) string {
|
||||||
fmt.Printf("Choose a number from below")
|
fmt.Printf("Choose a number from below")
|
||||||
|
@ -209,6 +214,22 @@ func OkRemote(name string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Runs the config helper for the remote if needed
|
||||||
|
func RemoteConfig(name string) {
|
||||||
|
fmt.Printf("Remote config\n")
|
||||||
|
fsName := ConfigFile.MustValue(name, "type")
|
||||||
|
if fsName == "" {
|
||||||
|
log.Fatalf("Couldn't find type of fs for %q", name)
|
||||||
|
}
|
||||||
|
f, err := Find(fsName)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Didn't find filing system: %v", err)
|
||||||
|
}
|
||||||
|
if f.Config != nil {
|
||||||
|
f.Config(name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Make a new remote
|
// Make a new remote
|
||||||
func NewRemote(name string) {
|
func NewRemote(name string) {
|
||||||
fmt.Printf("What type of source is it?\n")
|
fmt.Printf("What type of source is it?\n")
|
||||||
|
@ -225,6 +246,7 @@ func NewRemote(name string) {
|
||||||
for _, option := range fs.Options {
|
for _, option := range fs.Options {
|
||||||
ConfigFile.SetValue(name, option.Name, option.Choose())
|
ConfigFile.SetValue(name, option.Name, option.Choose())
|
||||||
}
|
}
|
||||||
|
RemoteConfig(name)
|
||||||
if OkRemote(name) {
|
if OkRemote(name) {
|
||||||
SaveConfig()
|
SaveConfig()
|
||||||
return
|
return
|
||||||
|
@ -246,6 +268,7 @@ func EditRemote(name string) {
|
||||||
ConfigFile.SetValue(name, key, newValue)
|
ConfigFile.SetValue(name, key, newValue)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
RemoteConfig(name)
|
||||||
if OkRemote(name) {
|
if OkRemote(name) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
1
fs/fs.go
1
fs/fs.go
|
@ -20,6 +20,7 @@ var (
|
||||||
type FsInfo struct {
|
type FsInfo struct {
|
||||||
Name string // name of this fs
|
Name string // name of this fs
|
||||||
NewFs func(string, string) (Fs, error) // create a new file system
|
NewFs func(string, string) (Fs, error) // create a new file system
|
||||||
|
Config func(string) // function to call to help with config
|
||||||
Options []Option
|
Options []Option
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user