taskcafe/internal/command/command.go

85 lines
1.8 KiB
Go
Raw Permalink Normal View History

2022-05-06 23:41:52 +02:00
package command
2020-07-16 01:20:08 +02:00
import (
"net/http"
"strings"
2022-05-06 23:41:52 +02:00
_ "github.com/lib/pq"
// "github.com/jordanknott/taskcafe/internal/config"
// "github.com/jordanknott/taskcafe/internal/utils"
"github.com/sirupsen/logrus"
2020-07-16 01:20:08 +02:00
"github.com/spf13/cobra"
"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.`
func VersionTemplate() string {
2022-05-06 23:41:52 +02:00
/*
info := utils.Version()
return fmt.Sprintf(`Version: %s
Commit: %s
Built: %s`, info.Version, info.CommitHash, info.BuildDate+"\n")
*/
return ""
}
2020-07-16 01:20:08 +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,
Version: VersionTemplate(),
2020-07-16 01:20:08 +02:00
}
var migration http.FileSystem
func init() {
cobra.OnInitialize(initConfig)
2022-05-06 23:41:52 +02:00
Formatter := new(logrus.TextFormatter)
Formatter.TimestampFormat = "02-01-2006 15:04:05"
Formatter.FullTimestamp = true
logrus.SetFormatter(Formatter)
logrus.SetLevel(logrus.InfoLevel)
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()
2022-05-06 23:41:52 +02:00
// config.InitDefaults()
err := viper.ReadInConfig()
if err == nil {
return
}
if _, ok := err.(viper.ConfigFileNotFoundError); !ok {
panic(err)
}
}
// Execute the root cobra command
2020-07-16 01:20:08 +02:00
func Execute() {
rootCmd.SetVersionTemplate(VersionTemplate())
2022-05-06 23:41:52 +02:00
rootCmd.AddCommand(newMigrateCmd(), newUserCmd(), newWebCmd())
2020-07-16 01:20:08 +02:00
rootCmd.Execute()
}