filebrowser/cmd/config_init.go
Henrique Dias 684366e050 feat: simplify flag adding
License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>

Former-commit-id: 520945c4cd979999ce7da8cc60544e1e390de3fe [formerly 5c73f94c28f67f0fb25ecff7ce999480ff0d873f] [formerly bdb85560ceeac89408c8588213ef88c5b774c8c7 [formerly fc06f642f2b1bce90430473fff9f6ac9638854d6]]
Former-commit-id: dc0c81b78cdec8656bd25dad84f9589486300d34 [formerly b18cd1e0bced8b34b31863fb7c4e714905bbf0d9]
Former-commit-id: cd84e54f28b9c56c3ced9da79f7fcb9a659f674a
2019-01-08 10:50:37 +00:00

56 lines
1.6 KiB
Go

package cmd
import (
"fmt"
"strings"
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/spf13/cobra"
)
func init() {
configCmd.AddCommand(configInitCmd)
addConfigFlags(configInitCmd.Flags())
}
var configInitCmd = &cobra.Command{
Use: "init",
Short: "Initialize a new database",
Long: `Initialize a new database to use with File Browser. All of
this options can be changed in the future with the command
"filebrowser config set". The user related flags apply
to the defaults when creating new users and you don't
override the options.`,
Args: cobra.NoArgs,
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
defaults := settings.UserDefaults{}
getUserDefaults(cmd, &defaults, true)
authMethod, auther := getAuthentication(cmd)
s := &settings.Settings{
Key: generateRandomBytes(64), // 256 bit
Signup: mustGetBool(cmd, "signup"),
Shell: strings.Split(strings.TrimSpace(mustGetString(cmd, "shell")), " "),
AuthMethod: authMethod,
Defaults: defaults,
Branding: settings.Branding{
Name: mustGetString(cmd, "branding.name"),
DisableExternal: mustGetBool(cmd, "branding.disableExternal"),
Files: mustGetString(cmd, "branding.files"),
},
}
err := d.store.Settings.Save(s)
checkErr(err)
err = d.store.Auth.Save(auther)
checkErr(err)
fmt.Printf(`
Congratulations! You've set up your database to use with File Browser.
Now add your first user via 'filebrowser users new' and then you just
need to call the main command to boot up the server.
`)
printSettings(s, auther)
}, pythonConfig{noDB: true}),
}