Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

config: add show/file subcommands which print the config/its path (fixes #1086)

Stefan85877f3adc45
diff --git a/cmd/config/config.go b/cmd/config/config.go
index dd94ccced..3b403146b 100644
--- a/cmd/config/config.go
+++ b/cmd/config/config.go
@@ -1,6 +1,9 @@
package config
import (
+ "fmt"
+ "os"
+
"github.com/ncw/rclone/cmd"
"github.com/ncw/rclone/fs"
"github.com/spf13/cobra"
@@ -11,10 +14,35 @@ func init() {
}
var commandDefintion = &cobra.Command{
- Use: "config",
+ Use: "config [function]",
Short: `Enter an interactive configuration session.`,
+ Long: "`rclone config`" + `
+ enters an interactive configuration sessions where you can setup
+new remotes and manage existing ones. You may also set or remove a password to
+protect your configuration.
+
+Additional functions:
+
+ * ` + "`rclone config edit`" + ` – same as above
+ * ` + "`rclone config file`" + ` – show path of configuration file in use
+ * ` + "`rclone config show`" + ` – print (decrypted) config file
+`,
Run: func(command *cobra.Command, args []string) {
- cmd.CheckArgs(0, 0, command, args)
- fs.EditConfig()
+ cmd.CheckArgs(0, 1, command, args)
+ if len(args) == 0 {
+ fs.EditConfig()
+ return
+ }
+
+ switch args[0] {
+ case "edit":
+ fs.EditConfig()
+ case "show":
+ fs.ShowConfig()
+ case "file":
+ fs.ShowConfigLocation()
+ default:
+ fmt.Fprintf(os.Stderr, "Unknown subcommand %q, %s only supports edit, show and file.\n", args[0], command.Name())
+ }
},
}
diff --git a/fs/config.go b/fs/config.go
index da8b51b67..67ff18f80 100644
--- a/fs/config.go
+++ b/fs/config.go
@@ -436,6 +436,8 @@ func LoadConfig() {
configData, _ = goconfig.LoadFromReader(&bytes.Buffer{})
} else if err != nil {
log.Fatalf("Failed to load config file %q: %v", ConfigPath, err)
+ } else {
+ Debugf(nil, "Using config file from %q", ConfigPath)
}
// Load filters
@@ -1096,6 +1098,29 @@ func CopyRemote(name string) {
SaveConfig()
}
+// ShowConfigLocation prints the location of the config file in use
+func ShowConfigLocation() {
+ if _, err := os.Stat(ConfigPath); os.IsNotExist(err) {
+ fmt.Println("Configuration file doesn't exist, but rclone will use this path:")
+ } else {
+ fmt.Println("Configuration file is stored at:")
+ }
+ fmt.Printf("%s\n", ConfigPath)
+}
+
+// ShowConfig prints the (unencrypted) config options
+func ShowConfig() {
+ var buf bytes.Buffer
+ if err := goconfig.SaveConfigData(configData, &buf); err != nil {
+ log.Fatalf("Failed to serialize config: %v", err)
+ }
+ str := buf.String()
+ if str == "" {
+ str = "; empty config\n"
+ }
+ fmt.Printf("%s", str)
+}
+
// EditConfig edits the config file interactively
func EditConfig() {
for {