From e08e35984c0855b2f956605d422b08b21b3163a2 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 15 Feb 2016 18:11:53 +0000 Subject: [PATCH] Add help to remote chooser in rclone config - fixes #43 --- amazonclouddrive/amazonclouddrive.go | 5 +++-- b2/b2.go | 5 +++-- drive/drive.go | 5 +++-- dropbox/dropbox.go | 7 ++++--- fs/config.go | 24 ++++++++++++++++++------ fs/fs.go | 20 +++++++++++++++++++- googlecloudstorage/googlecloudstorage.go | 5 +++-- hubic/hubic.go | 5 +++-- local/local.go | 5 +++-- onedrive/onedrive.go | 5 +++-- s3/s3.go | 9 +++++---- swift/swift.go | 5 +++-- yandex/yandex.go | 5 +++-- 13 files changed, 73 insertions(+), 32 deletions(-) diff --git a/amazonclouddrive/amazonclouddrive.go b/amazonclouddrive/amazonclouddrive.go index 5a5869748..094d04814 100644 --- a/amazonclouddrive/amazonclouddrive.go +++ b/amazonclouddrive/amazonclouddrive.go @@ -63,8 +63,9 @@ var ( // Register with Fs func init() { fs.Register(&fs.RegInfo{ - Name: "amazon cloud drive", - NewFs: NewFs, + Name: "amazon cloud drive", + Description: "Amazon Cloud Drive", + NewFs: NewFs, Config: func(name string) { err := oauthutil.Config("amazon cloud drive", name, acdConfig) if err != nil { diff --git a/b2/b2.go b/b2/b2.go index e7fc3ab35..8891fe76e 100644 --- a/b2/b2.go +++ b/b2/b2.go @@ -40,8 +40,9 @@ const ( // Register with Fs func init() { fs.Register(&fs.RegInfo{ - Name: "b2", - NewFs: NewFs, + Name: "b2", + Description: "Backblaze B2", + NewFs: NewFs, Options: []fs.Option{{ Name: "account", Help: "Account ID", diff --git a/drive/drive.go b/drive/drive.go index d541420e2..034edd9de 100644 --- a/drive/drive.go +++ b/drive/drive.go @@ -85,8 +85,9 @@ var ( // Register with Fs func init() { fs.Register(&fs.RegInfo{ - Name: "drive", - NewFs: NewFs, + Name: "drive", + Description: "Google Drive", + NewFs: NewFs, Config: func(name string) { err := oauthutil.Config("drive", name, driveConfig) if err != nil { diff --git a/dropbox/dropbox.go b/dropbox/dropbox.go index 73aa8a1e9..7ae1cc4ef 100644 --- a/dropbox/dropbox.go +++ b/dropbox/dropbox.go @@ -45,9 +45,10 @@ var ( // Register with Fs func init() { fs.Register(&fs.RegInfo{ - Name: "dropbox", - NewFs: NewFs, - Config: configHelper, + Name: "dropbox", + Description: "Dropbox", + NewFs: NewFs, + Config: configHelper, Options: []fs.Option{{ Name: "app_key", Help: "Dropbox App Key - leave blank normally.", diff --git a/fs/config.go b/fs/config.go index f46e54d77..db6221657 100644 --- a/fs/config.go +++ b/fs/config.go @@ -673,14 +673,26 @@ func ChooseOption(o *Option) string { return ReadLine() } +// fsOption returns an Option describing the possible remotes +func fsOption() *Option { + o := &Option{ + Name: "Storage", + Help: "Type of storage to configure.", + } + for _, item := range fsRegistry { + example := OptionExample{ + Value: item.Name, + Help: item.Description, + } + o.Examples = append(o.Examples, example) + } + o.Examples.Sort() + return o +} + // NewRemote make a new remote from its name func NewRemote(name string) { - fmt.Printf("What type of source is it?\n") - types := []string{} - for _, item := range fsRegistry { - types = append(types, item.Name) - } - newType := Choose("type", types, nil, false) + newType := ChooseOption(fsOption()) ConfigFile.SetValue(name, "type", newType) fs, err := Find(newType) if err != nil { diff --git a/fs/fs.go b/fs/fs.go index 18140a376..13870b118 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -7,6 +7,7 @@ import ( "log" "path/filepath" "regexp" + "sort" "time" ) @@ -36,6 +37,8 @@ var ( type RegInfo struct { // Name of this fs Name string + // Description of this fs - defaults to Name + Description string // Create a new file system. If root refers to an existing // object, then it should return a Fs which only returns that // object. @@ -51,9 +54,24 @@ type Option struct { Name string Help string Optional bool - Examples []OptionExample + Examples OptionExamples } +// OptionExamples is a slice of examples +type OptionExamples []OptionExample + +// Len is part of sort.Interface. +func (os OptionExamples) Len() int { return len(os) } + +// Swap is part of sort.Interface. +func (os OptionExamples) Swap(i, j int) { os[i], os[j] = os[j], os[i] } + +// Less is part of sort.Interface. +func (os OptionExamples) Less(i, j int) bool { return os[i].Help < os[j].Help } + +// Sort sorts an OptionExamples +func (os OptionExamples) Sort() { sort.Sort(os) } + // OptionExample describes an example for an Option type OptionExample struct { Value string diff --git a/googlecloudstorage/googlecloudstorage.go b/googlecloudstorage/googlecloudstorage.go index aa844e38b..fad5883fd 100644 --- a/googlecloudstorage/googlecloudstorage.go +++ b/googlecloudstorage/googlecloudstorage.go @@ -56,8 +56,9 @@ var ( // Register with Fs func init() { fs.Register(&fs.RegInfo{ - Name: "google cloud storage", - NewFs: NewFs, + Name: "google cloud storage", + Description: "Google Cloud Storage (this is not Google Drive)", + NewFs: NewFs, Config: func(name string) { err := oauthutil.Config("google cloud storage", name, storageConfig) if err != nil { diff --git a/hubic/hubic.go b/hubic/hubic.go index 44752c575..2fc63faac 100644 --- a/hubic/hubic.go +++ b/hubic/hubic.go @@ -45,8 +45,9 @@ var ( // Register with Fs func init() { fs.Register(&fs.RegInfo{ - Name: "hubic", - NewFs: NewFs, + Name: "hubic", + Description: "Hubic", + NewFs: NewFs, Config: func(name string) { err := oauthutil.Config("hubic", name, oauthConfig) if err != nil { diff --git a/local/local.go b/local/local.go index a2f70845f..cde0100c3 100644 --- a/local/local.go +++ b/local/local.go @@ -20,8 +20,9 @@ import ( // Register with Fs func init() { fsi := &fs.RegInfo{ - Name: "local", - NewFs: NewFs, + Name: "local", + Description: "Local Disk", + NewFs: NewFs, Options: []fs.Option{fs.Option{ Name: "nounc", Help: "Disable UNC (long path names) conversion on Windows", diff --git a/onedrive/onedrive.go b/onedrive/onedrive.go index f7684ca74..fc557cc36 100644 --- a/onedrive/onedrive.go +++ b/onedrive/onedrive.go @@ -56,8 +56,9 @@ var ( // Register with Fs func init() { fs.Register(&fs.RegInfo{ - Name: "onedrive", - NewFs: NewFs, + Name: "onedrive", + Description: "Microsoft OneDrive", + NewFs: NewFs, Config: func(name string) { err := oauthutil.Config("onedrive", name, oauthConfig) if err != nil { diff --git a/s3/s3.go b/s3/s3.go index 4334bc0c5..5dbbd3470 100644 --- a/s3/s3.go +++ b/s3/s3.go @@ -41,8 +41,9 @@ import ( // Register with Fs func init() { fs.Register(&fs.RegInfo{ - Name: "s3", - NewFs: NewFs, + Name: "s3", + Description: "Amazon S3 (also Dreamhost, Ceph)", + NewFs: NewFs, // AWS endpoints: http://docs.amazonwebservices.com/general/latest/gr/rande.html#s3_region Options: []fs.Option{{ Name: "env_auth", @@ -94,10 +95,10 @@ func init() { Help: "South America (Sao Paulo) Region\nNeeds location constraint sa-east-1.", }, { Value: "other-v2-signature", - Help: "If using an S3 clone that only understands v2 signatures - eg Ceph - set this and make sure you set the endpoint.", + Help: "If using an S3 clone that only understands v2 signatures\neg Ceph/Dreamhost\nset this and make sure you set the endpoint.", }, { Value: "other-v4-signature", - Help: "If using an S3 clone that understands v4 signatures set this and make sure you set the endpoint.", + Help: "If using an S3 clone that understands v4 signatures set this\nand make sure you set the endpoint.", }}, }, { Name: "endpoint", diff --git a/swift/swift.go b/swift/swift.go index 8dddf97e8..ab317b852 100644 --- a/swift/swift.go +++ b/swift/swift.go @@ -30,8 +30,9 @@ var ( // Register with Fs func init() { fs.Register(&fs.RegInfo{ - Name: "swift", - NewFs: NewFs, + Name: "swift", + Description: "Openstack Swift (Rackspace Cloud Files, Memset Memstore, OVH)", + NewFs: NewFs, Options: []fs.Option{{ Name: "user", Help: "User name to log in.", diff --git a/yandex/yandex.go b/yandex/yandex.go index 82277fc57..837fbba0b 100644 --- a/yandex/yandex.go +++ b/yandex/yandex.go @@ -42,8 +42,9 @@ var ( // Register with Fs func init() { fs.Register(&fs.RegInfo{ - Name: "yandex", - NewFs: NewFs, + Name: "yandex", + Description: "Yandex Disk", + NewFs: NewFs, Config: func(name string) { err := oauthutil.Config("yandex", name, oauthConfig) if err != nil {