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

This commit is contained in:
Stefan
2017-09-19 17:59:19 +02:00
committed by GitHub
parent 87335de8a8
commit 85877f3adc
2 changed files with 56 additions and 3 deletions
+25
View File
@@ -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 {