2019-01-05 22:44:33 +00:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/filebrowser/filebrowser/v2/auth"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/pflag"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
configCmd.AddCommand(configSetCmd)
|
2019-01-08 10:50:37 +00:00
|
|
|
addConfigFlags(configSetCmd.Flags())
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var configSetCmd = &cobra.Command{
|
|
|
|
Use: "set",
|
|
|
|
Short: "Updates the configuration",
|
|
|
|
Long: `Updates the configuration. Set the flags for the options
|
2019-01-08 16:37:02 +00:00
|
|
|
you want to change. Other options will remain unchanged.`,
|
2019-01-05 22:44:33 +00:00
|
|
|
Args: cobra.NoArgs,
|
2019-01-07 20:24:23 +00:00
|
|
|
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
2019-01-08 14:07:55 +00:00
|
|
|
flags := cmd.Flags()
|
|
|
|
set, err := d.store.Settings.Get()
|
|
|
|
checkErr(err)
|
|
|
|
|
|
|
|
ser, err := d.store.Settings.GetServer()
|
2019-01-05 22:44:33 +00:00
|
|
|
checkErr(err)
|
|
|
|
|
|
|
|
hasAuth := false
|
2019-01-08 14:07:55 +00:00
|
|
|
flags.Visit(func(flag *pflag.Flag) {
|
2019-01-05 22:44:33 +00:00
|
|
|
switch flag.Name {
|
2019-01-08 14:07:55 +00:00
|
|
|
case "baseurl":
|
|
|
|
ser.BaseURL = mustGetString(flags, flag.Name)
|
|
|
|
case "root":
|
|
|
|
ser.Root = mustGetString(flags, flag.Name)
|
|
|
|
case "cert":
|
|
|
|
ser.TLSCert = mustGetString(flags, flag.Name)
|
|
|
|
case "key":
|
|
|
|
ser.TLSKey = mustGetString(flags, flag.Name)
|
|
|
|
case "address":
|
|
|
|
ser.Address = mustGetString(flags, flag.Name)
|
|
|
|
case "port":
|
|
|
|
ser.Port = mustGetString(flags, flag.Name)
|
|
|
|
case "log":
|
|
|
|
ser.Log = mustGetString(flags, flag.Name)
|
2019-01-05 22:44:33 +00:00
|
|
|
case "signup":
|
2019-01-08 14:07:55 +00:00
|
|
|
set.Signup = mustGetBool(flags, flag.Name)
|
2019-01-05 22:44:33 +00:00
|
|
|
case "auth.method":
|
|
|
|
hasAuth = true
|
|
|
|
case "shell":
|
2019-01-08 14:07:55 +00:00
|
|
|
set.Shell = strings.Split(strings.TrimSpace(mustGetString(flags, flag.Name)), " ")
|
2019-01-05 22:44:33 +00:00
|
|
|
case "branding.name":
|
2019-01-08 14:07:55 +00:00
|
|
|
set.Branding.Name = mustGetString(flags, flag.Name)
|
2019-01-05 22:44:33 +00:00
|
|
|
case "branding.disableExternal":
|
2019-01-08 14:07:55 +00:00
|
|
|
set.Branding.DisableExternal = mustGetBool(flags, flag.Name)
|
2019-01-05 22:44:33 +00:00
|
|
|
case "branding.files":
|
2019-01-08 14:07:55 +00:00
|
|
|
set.Branding.Files = mustGetString(flags, flag.Name)
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2019-01-08 14:07:55 +00:00
|
|
|
getUserDefaults(flags, &set.Defaults, false)
|
2019-01-05 22:44:33 +00:00
|
|
|
|
|
|
|
var auther auth.Auther
|
|
|
|
if hasAuth {
|
2019-01-08 14:07:55 +00:00
|
|
|
set.AuthMethod, auther = getAuthentication(flags)
|
2019-01-07 20:24:23 +00:00
|
|
|
err = d.store.Auth.Save(auther)
|
2019-01-05 22:44:33 +00:00
|
|
|
checkErr(err)
|
|
|
|
} else {
|
2019-01-08 14:07:55 +00:00
|
|
|
auther, err = d.store.Auth.Get(set.AuthMethod)
|
2019-01-05 22:44:33 +00:00
|
|
|
checkErr(err)
|
|
|
|
}
|
|
|
|
|
2019-01-08 14:07:55 +00:00
|
|
|
err = d.store.Settings.Save(set)
|
|
|
|
checkErr(err)
|
|
|
|
err = d.store.Settings.SaveServer(ser)
|
2019-01-05 22:44:33 +00:00
|
|
|
checkErr(err)
|
2019-01-08 14:07:55 +00:00
|
|
|
printSettings(ser, set, auther)
|
2019-01-07 20:24:23 +00:00
|
|
|
}, pythonConfig{}),
|
2019-01-05 22:44:33 +00:00
|
|
|
}
|