diff options
-rw-r--r-- | CHANGELOG.md | 9 | ||||
-rw-r--r-- | cmd/rr/cmd/root.go | 30 | ||||
-rw-r--r-- | cmd/rr/main.go | 3 | ||||
-rw-r--r-- | cmd/util/config.go | 4 | ||||
-rw-r--r-- | cmd/util/cprint.go | 9 |
5 files changed, 47 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index fc4f5c96..27dd0d60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,15 @@ CHANGELOG ========= +v1.3.5 (14.02.2019) +------------------- +- new console flag `l` to define log formatting + * **color|default** - colorized output + * **plain** - disable all colorization + * **json** - output as json +- new console flag `w` to specify work dir +- added ability to work without config file when at least one `overwrite` option has been specified + v1.3.4 (02.02.2019) ------------------- - bugfix: invalid content type detection for urlencoded form requests with custom encoding by @Alex-Bond diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go index ceeeb840..5fa76b87 100644 --- a/cmd/rr/cmd/root.go +++ b/cmd/rr/cmd/root.go @@ -30,8 +30,8 @@ import ( // Service bus for all the commands. var ( - cfgFile string - override []string + cfgFile, workDir, logFormat string + override []string // Verbose enables verbosity mode (container specific). Verbose bool @@ -68,9 +68,12 @@ func Execute() { } func init() { - CLI.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "Verbose output") + CLI.PersistentFlags().BoolVarP(&Verbose, "verbose", "v", false, "verbose output") CLI.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "debug mode") + CLI.PersistentFlags().StringVarP(&logFormat, "logFormat", "l", "color", "select log formatter (color, json, plain)") CLI.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is .rr.yaml)") + CLI.PersistentFlags().StringVarP(&workDir, "workDir", "w", "", "work directory") + CLI.PersistentFlags().StringArrayVarP( &override, "override", @@ -84,15 +87,36 @@ func init() { Logger.SetLevel(logrus.DebugLevel) } + configureLogger(logFormat) + cfg, err := util.LoadConfig(cfgFile, []string{"."}, ".rr", override) if err != nil { Logger.Warnf("config: %s", err) return } + if workDir != "" { + if err := os.Chdir(workDir); err != nil { + util.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err) + os.Exit(1) + } + } + if err := Container.Init(cfg); err != nil { util.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err) os.Exit(1) } }) } + +func configureLogger(format string) { + switch format { + case "color", "default": + util.EnableColors = true + Logger.Formatter = &logrus.TextFormatter{ForceColors: true} + case "plain": + Logger.Formatter = &logrus.TextFormatter{DisableColors: true} + case "json": + Logger.Formatter = &logrus.JSONFormatter{} + } +} diff --git a/cmd/rr/main.go b/cmd/rr/main.go index 4d2a06b4..54915957 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -23,7 +23,6 @@ package main import ( - "github.com/sirupsen/logrus" rr "github.com/spiral/roadrunner/cmd/rr/cmd" // services (plugins) @@ -42,8 +41,6 @@ func main() { rr.Container.Register(http.ID, &http.Service{}) rr.Container.Register(static.ID, &static.Service{}) - rr.Logger.Formatter = &logrus.TextFormatter{ForceColors: true} - // you can register additional commands using cmd.CLI rr.Execute() } diff --git a/cmd/util/config.go b/cmd/util/config.go index a829f44c..a354b132 100644 --- a/cmd/util/config.go +++ b/cmd/util/config.go @@ -66,7 +66,9 @@ func LoadConfig(cfgFile string, path []string, name string, flags []string) (*co // If a cfg file is found, read it in. if err := cfg.ReadInConfig(); err != nil { - return nil, err + if len(flags) == 0 { + return nil, err + } } if len(flags) != 0 { diff --git a/cmd/util/cprint.go b/cmd/util/cprint.go index 0985de62..61199c4a 100644 --- a/cmd/util/cprint.go +++ b/cmd/util/cprint.go @@ -7,7 +7,10 @@ import ( "strings" ) -var reg *regexp.Regexp +var ( + reg *regexp.Regexp + EnableColors bool +) func init() { reg, _ = regexp.Compile(`<([^>]+)>`) @@ -21,6 +24,10 @@ func Printf(format string, args ...interface{}) { // Sprintf works identically to fmt.Sprintf but adds `<white+hb>color formatting support for CLI</reset>`. func Sprintf(format string, args ...interface{}) string { format = reg.ReplaceAllStringFunc(format, func(s string) string { + if !EnableColors { + return "" + } + return ansi.ColorCode(strings.Trim(s, "<>/")) }) |