filebrowser/cmd/config_init.go
Henrique Dias 77e1fe83db feat: wrap commands to send info (#612)
Wrap commands in a better way to pass storage

Former-commit-id: 9a3790c193936b53fe3826d1e051795efd30670b [formerly 04a9f34933a162cf4a98bc1e019f0d6c6404aae7] [formerly ab9be7f27b55a94e6a0f053df6908e357d4b396c [formerly 01ff03e426]]
Former-commit-id: ae7b61281dec2b5527f6032dc6f8c1bd8bb51296 [formerly 780ccc3b166e72bf53114bbfc0a95c0b7ffd8656]
Former-commit-id: 68ee8f7f3931f8e571b0188c96951077d6529cd7
2019-01-07 20:24:23 +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)
}
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}),
}