Files
filebrowser/cmd/config_init.go
T

62 lines
1.4 KiB
Go
Raw Normal View History

2019-01-05 22:44:33 +00:00
package cmd
import (
"fmt"
"github.com/spf13/cobra"
2020-06-01 01:12:36 +02:00
"github.com/filebrowser/filebrowser/v2/settings"
2019-01-05 22:44:33 +00:00
)
func init() {
configCmd.AddCommand(configInitCmd)
2019-01-08 10:50:37 +00:00
addConfigFlags(configInitCmd.Flags())
2019-01-05 22:44:33 +00:00
}
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
2019-01-08 16:37:02 +00:00
'filebrowser config set'. The user related flags apply
2019-01-05 22:44:33 +00:00
to the defaults when creating new users and you don't
override the options.`,
Args: cobra.NoArgs,
2025-11-18 11:29:28 +01:00
RunE: withStore(func(cmd *cobra.Command, _ []string, st *store) error {
2019-01-08 14:07:55 +00:00
flags := cmd.Flags()
// Initialize config
s := &settings.Settings{Key: generateKey()}
ser := &settings.Server{}
// Fill config with options
auther, err := getSettings(flags, s, ser, nil, true)
if err != nil {
return err
}
// Save updated config
2025-11-18 11:29:28 +01:00
err = st.Settings.Save(s)
if err != nil {
return err
}
2025-11-18 11:29:28 +01:00
err = st.Settings.SaveServer(ser)
if err != nil {
return err
}
2025-11-18 11:29:28 +01:00
err = st.Auth.Save(auther)
if err != nil {
return err
}
2019-01-05 22:44:33 +00:00
fmt.Printf(`
Congratulations! You've set up your database to use with File Browser.
2020-11-05 00:47:36 +08:00
Now add your first user via 'filebrowser users add' and then you just
2019-01-05 22:44:33 +00:00
need to call the main command to boot up the server.
`)
return printSettings(ser, s, auther)
2025-11-18 11:29:28 +01:00
}, storeOptions{expectsNoDatabase: true}),
2019-01-05 22:44:33 +00:00
}