Reorganize cmd init functions
This commit is contained in:
parent
d9d00ba60c
commit
f5e44d9eb3
4 changed files with 22 additions and 7 deletions
|
@ -31,10 +31,6 @@ import (
|
||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
|
||||||
cobra.OnInitialize(initialize)
|
|
||||||
}
|
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "vikunja",
|
Use: "vikunja",
|
||||||
Short: "Vikunja is the to-do app to organize your life.",
|
Short: "Vikunja is the to-do app to organize your life.",
|
||||||
|
@ -47,7 +43,8 @@ alpine areas of the Andes and a relative of the llama.
|
||||||
Vikunja is a self-hosted To-Do list application with a web app and mobile apps for all platforms. It is licensed under the GPLv3.
|
Vikunja is a self-hosted To-Do list application with a web app and mobile apps for all platforms. It is licensed under the GPLv3.
|
||||||
|
|
||||||
Find more info at vikunja.io.`,
|
Find more info at vikunja.io.`,
|
||||||
Run: webCmd.Run,
|
PreRun: webCmd.PreRun,
|
||||||
|
Run: webCmd.Run,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Execute starts the application
|
// Execute starts the application
|
||||||
|
@ -58,8 +55,8 @@ func Execute() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initializes all kinds of things in the right order
|
// Will only fullInit config, redis, logger but no db connection.
|
||||||
func initialize() {
|
func lightInit() {
|
||||||
// Init the config
|
// Init the config
|
||||||
config.InitConfig()
|
config.InitConfig()
|
||||||
|
|
||||||
|
@ -68,6 +65,12 @@ func initialize() {
|
||||||
|
|
||||||
// Set logger
|
// Set logger
|
||||||
log.InitLogger()
|
log.InitLogger()
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initializes all kinds of things in the right order
|
||||||
|
func fullInit() {
|
||||||
|
|
||||||
|
lightInit()
|
||||||
|
|
||||||
// Run the migrations
|
// Run the migrations
|
||||||
migration.Migrate(nil)
|
migration.Migrate(nil)
|
||||||
|
|
|
@ -35,6 +35,9 @@ func init() {
|
||||||
var migrateCmd = &cobra.Command{
|
var migrateCmd = &cobra.Command{
|
||||||
Use: "migrate",
|
Use: "migrate",
|
||||||
Short: "Run all database migrations which didn't already run.",
|
Short: "Run all database migrations which didn't already run.",
|
||||||
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
lightInit()
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
migration.Migrate(nil)
|
migration.Migrate(nil)
|
||||||
},
|
},
|
||||||
|
|
|
@ -30,6 +30,12 @@ var testmailCmd = &cobra.Command{
|
||||||
Use: "testmail [email]",
|
Use: "testmail [email]",
|
||||||
Short: "Send a test mail using the configured smtp connection",
|
Short: "Send a test mail using the configured smtp connection",
|
||||||
Args: cobra.ExactArgs(1),
|
Args: cobra.ExactArgs(1),
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
lightInit()
|
||||||
|
|
||||||
|
// Start the mail daemon
|
||||||
|
mail.StartMailDaemon()
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
log.Info("Sending testmail...")
|
log.Info("Sending testmail...")
|
||||||
email := args[0]
|
email := args[0]
|
||||||
|
|
|
@ -36,6 +36,9 @@ func init() {
|
||||||
var webCmd = &cobra.Command{
|
var webCmd = &cobra.Command{
|
||||||
Use: "web",
|
Use: "web",
|
||||||
Short: "Starts the rest api web server",
|
Short: "Starts the rest api web server",
|
||||||
|
PreRun: func(cmd *cobra.Command, args []string) {
|
||||||
|
fullInit()
|
||||||
|
},
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
|
|
||||||
// Version notification
|
// Version notification
|
||||||
|
|
Loading…
Add table
Reference in a new issue