mirror of
https://github.com/m1k1o/neko.git
synced 2025-05-19 03:57:06 +02:00
add v2 compatible config.
This commit is contained in:
parent
b5c3f8d4a6
commit
e0a4b39cd5
10 changed files with 889 additions and 0 deletions
|
@ -2,6 +2,8 @@ package config
|
|||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
@ -59,6 +61,15 @@ func (Root) Init(cmd *cobra.Command) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (Root) InitV2(cmd *cobra.Command) error {
|
||||
cmd.PersistentFlags().BoolP("logs", "l", false, "save logs to file")
|
||||
if err := viper.BindPFlag("logs", cmd.PersistentFlags().Lookup("logs")); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Root) Set() {
|
||||
s.Config = viper.GetString("config")
|
||||
|
||||
|
@ -95,3 +106,18 @@ func (s *Root) Set() {
|
|||
s.LogNocolor = true
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Root) SetV2() {
|
||||
if viper.IsSet("logs") {
|
||||
if viper.GetBool("logs") {
|
||||
logs := filepath.Join(".", "logs")
|
||||
if runtime.GOOS == "linux" {
|
||||
logs = "/var/log/neko"
|
||||
}
|
||||
s.LogDir = logs
|
||||
} else {
|
||||
s.LogDir = ""
|
||||
}
|
||||
log.Warn().Msg("you are using v2 configuration 'NEKO_LOGS' which is deprecated, please use 'NEKO_LOG_DIR=/path/to/logs' instead")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue