2020-07-16 01:20:08 +02:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-08-13 05:17:42 +02:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2020-12-30 02:37:14 +01:00
|
|
|
"github.com/jordanknott/taskcafe/internal/utils"
|
2020-07-16 01:20:08 +02:00
|
|
|
"github.com/spf13/cobra"
|
2020-08-13 05:17:42 +02:00
|
|
|
"github.com/spf13/viper"
|
2020-07-16 01:20:08 +02:00
|
|
|
)
|
|
|
|
|
2020-08-07 03:50:35 +02:00
|
|
|
const mainDescription = `Taskcafé is an open soure project management
|
2020-07-16 01:20:08 +02:00
|
|
|
system written in Golang & React.`
|
|
|
|
|
2020-12-30 02:37:14 +01:00
|
|
|
func VersionTemplate() string {
|
|
|
|
info := utils.Version()
|
|
|
|
return fmt.Sprintf(`Version: %s
|
2020-07-16 01:20:08 +02:00
|
|
|
Commit: %s
|
2020-12-30 02:37:14 +01:00
|
|
|
Built: %s`, info.Version, info.CommitHash, info.BuildDate+"\n")
|
|
|
|
}
|
2020-07-16 01:20:08 +02:00
|
|
|
|
2020-08-13 05:17:42 +02:00
|
|
|
var cfgFile string
|
2020-07-16 01:20:08 +02:00
|
|
|
|
|
|
|
var rootCmd = &cobra.Command{
|
2020-08-07 03:50:35 +02:00
|
|
|
Use: "taskcafe",
|
2020-07-16 01:20:08 +02:00
|
|
|
Long: mainDescription,
|
2020-12-30 02:37:14 +01:00
|
|
|
Version: VersionTemplate(),
|
2020-07-16 01:20:08 +02:00
|
|
|
}
|
|
|
|
|
2020-08-13 05:17:42 +02:00
|
|
|
var migration http.FileSystem
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
cobra.OnInitialize(initConfig)
|
|
|
|
|
|
|
|
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file path")
|
|
|
|
migration = http.Dir("./migrations")
|
|
|
|
}
|
|
|
|
|
|
|
|
func initConfig() {
|
|
|
|
if cfgFile != "" {
|
|
|
|
// Use config file from the flag.
|
|
|
|
viper.SetConfigFile(cfgFile)
|
|
|
|
} else {
|
|
|
|
// Search config in home directory with name ".cobra" (without extension).
|
|
|
|
viper.AddConfigPath("./conf")
|
|
|
|
viper.AddConfigPath(".")
|
|
|
|
viper.AddConfigPath("/etc/taskcafe")
|
|
|
|
viper.SetConfigName("taskcafe")
|
|
|
|
}
|
|
|
|
|
|
|
|
viper.SetEnvPrefix("TASKCAFE")
|
|
|
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
|
|
|
viper.AutomaticEnv()
|
|
|
|
|
2020-08-19 07:34:27 +02:00
|
|
|
err := viper.ReadInConfig()
|
2020-08-22 06:29:08 +02:00
|
|
|
if err == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
|
2020-08-13 05:17:42 +02:00
|
|
|
panic(err)
|
|
|
|
}
|
2020-10-21 01:52:09 +02:00
|
|
|
|
|
|
|
viper.SetDefault("server.hostname", "0.0.0.0:3333")
|
|
|
|
viper.SetDefault("database.host", "127.0.0.1")
|
|
|
|
viper.SetDefault("database.name", "taskcafe")
|
|
|
|
viper.SetDefault("database.user", "taskcafe")
|
|
|
|
viper.SetDefault("database.password", "taskcafe_test")
|
|
|
|
|
|
|
|
viper.SetDefault("queue.broker", "amqp://guest:guest@localhost:5672/")
|
|
|
|
viper.SetDefault("queue.store", "memcache://localhost:11211")
|
|
|
|
|
2020-08-13 05:17:42 +02:00
|
|
|
}
|
|
|
|
|
2020-08-21 01:11:24 +02:00
|
|
|
// Execute the root cobra command
|
2020-07-16 01:20:08 +02:00
|
|
|
func Execute() {
|
2020-10-21 01:52:09 +02:00
|
|
|
viper.SetDefault("server.hostname", "0.0.0.0:3333")
|
|
|
|
viper.SetDefault("database.host", "127.0.0.1")
|
|
|
|
viper.SetDefault("database.name", "taskcafe")
|
|
|
|
viper.SetDefault("database.user", "taskcafe")
|
|
|
|
viper.SetDefault("database.password", "taskcafe_test")
|
2020-10-21 01:52:09 +02:00
|
|
|
viper.SetDefault("database.port", "5432")
|
2020-12-31 04:10:34 +01:00
|
|
|
viper.SetDefault("security.token_expiration", "15m")
|
2020-10-21 01:52:09 +02:00
|
|
|
|
|
|
|
viper.SetDefault("queue.broker", "amqp://guest:guest@localhost:5672/")
|
|
|
|
viper.SetDefault("queue.store", "memcache://localhost:11211")
|
|
|
|
|
2020-12-30 02:37:14 +01:00
|
|
|
rootCmd.SetVersionTemplate(VersionTemplate())
|
2021-04-29 04:32:19 +02:00
|
|
|
rootCmd.AddCommand(newWebCmd(), newMigrateCmd(), newWorkerCmd(), newResetPasswordCmd(), newSeedCmd())
|
2020-07-16 01:20:08 +02:00
|
|
|
rootCmd.Execute()
|
|
|
|
}
|