From 1b3a49929bd4eaca5abdb95a564a342253b7a97c Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sun, 16 Mar 2014 13:54:43 +0000 Subject: [PATCH] Add ability for FS to have a Config helper function run --- fs/config.go | 23 +++++++++++++++++++++++ fs/fs.go | 1 + 2 files changed, 24 insertions(+) diff --git a/fs/config.go b/fs/config.go index 6321601be..01b5bc019 100644 --- a/fs/config.go +++ b/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 func Choose(what string, defaults, help []string, newOk bool) string { fmt.Printf("Choose a number from below") @@ -209,6 +214,22 @@ func OkRemote(name string) bool { 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 func NewRemote(name string) { fmt.Printf("What type of source is it?\n") @@ -225,6 +246,7 @@ func NewRemote(name string) { for _, option := range fs.Options { ConfigFile.SetValue(name, option.Name, option.Choose()) } + RemoteConfig(name) if OkRemote(name) { SaveConfig() return @@ -246,6 +268,7 @@ func EditRemote(name string) { ConfigFile.SetValue(name, key, newValue) } } + RemoteConfig(name) if OkRemote(name) { break } diff --git a/fs/fs.go b/fs/fs.go index e20e4b5eb..c76747967 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -20,6 +20,7 @@ var ( type FsInfo struct { Name string // name of this fs NewFs func(string, string) (Fs, error) // create a new file system + Config func(string) // function to call to help with config Options []Option }