summaryrefslogtreecommitdiff
path: root/cmd/rr
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/rr')
-rw-r--r--cmd/rr/cmd/root.go36
-rw-r--r--cmd/rr/http/debug.go20
-rw-r--r--cmd/rr/main.go11
3 files changed, 41 insertions, 26 deletions
diff --git a/cmd/rr/cmd/root.go b/cmd/rr/cmd/root.go
index 595395c0..5e936580 100644
--- a/cmd/rr/cmd/root.go
+++ b/cmd/rr/cmd/root.go
@@ -24,17 +24,20 @@ import (
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
- "github.com/spiral/roadrunner/cmd/rr/debug"
"github.com/spiral/roadrunner/cmd/rr/utils"
"github.com/spiral/roadrunner/service"
- "github.com/spiral/roadrunner/service/http"
"os"
)
// Service bus for all the commands.
var (
- cfgFile string
- verbose, debugMode bool
+ cfgFile string
+
+ // Verbose enables verbosity mode (container specific).
+ Verbose bool
+
+ // Debug enables debug mode (service specific).
+ Debug bool
// Logger - shared logger.
Logger = logrus.New()
@@ -78,6 +81,13 @@ func (w *ViperWrapper) Unmarshal(out interface{}) error {
// Execute adds all child commands to the CLI command and sets flags appropriately.
// This is called by main.main(). It only needs to happen once to the CLI.
func Execute() {
+ if cfg := initConfig(cfgFile, []string{"."}, ".rr"); cfg != nil {
+ if err := Container.Init(cfg); err != nil {
+ utils.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
+ os.Exit(1)
+ }
+ }
+
if err := CLI.Execute(); err != nil {
utils.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
os.Exit(1)
@@ -85,26 +95,14 @@ func Execute() {
}
func init() {
- CLI.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "verbose output")
- CLI.PersistentFlags().BoolVarP(&debugMode, "debug", "d", false, "debug mode")
+ CLI.PersistentFlags().BoolVarP(&Verbose, "Verbose", "v", false, "Verbose output")
+ CLI.PersistentFlags().BoolVarP(&Debug, "debug", "d", false, "debug mode")
CLI.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is .rr.yaml)")
cobra.OnInitialize(func() {
- if verbose {
+ if Verbose {
Logger.SetLevel(logrus.DebugLevel)
}
-
- if debugMode {
- svc, _ := Container.Get(http.ID)
- svc.(*http.Service).AddListener(debug.Listener(Logger))
- }
-
- if cfg := initConfig(cfgFile, []string{"."}, ".rr"); cfg != nil {
- if err := Container.Init(cfg); err != nil {
- utils.Printf("<red+hb>Error:</reset> <red>%s</reset>\n", err)
- os.Exit(1)
- }
- }
})
}
diff --git a/cmd/rr/http/debug.go b/cmd/rr/http/debug.go
new file mode 100644
index 00000000..f69e10a8
--- /dev/null
+++ b/cmd/rr/http/debug.go
@@ -0,0 +1,20 @@
+package http
+
+import (
+ rr "github.com/spiral/roadrunner/cmd/rr/cmd"
+
+ "github.com/spf13/cobra"
+ "github.com/spiral/roadrunner/cmd/rr/debug"
+ "github.com/spiral/roadrunner/service/http"
+)
+
+func init() {
+ cobra.OnInitialize(func() {
+ if rr.Debug {
+ svc, _ := rr.Container.Get(http.ID)
+ if svc, ok := svc.(*http.Service); ok {
+ svc.AddListener(debug.Listener(rr.Logger))
+ }
+ }
+ })
+}
diff --git a/cmd/rr/main.go b/cmd/rr/main.go
index 01a5aaf3..18e22cdd 100644
--- a/cmd/rr/main.go
+++ b/cmd/rr/main.go
@@ -23,9 +23,7 @@
package main
import (
- // colorful logging
"github.com/sirupsen/logrus"
-
rr "github.com/spiral/roadrunner/cmd/rr/cmd"
// services (plugins)
@@ -34,19 +32,18 @@ import (
"github.com/spiral/roadrunner/service/rpc"
"github.com/spiral/roadrunner/service/static"
- // additional command handlers
+ // additional command and debug handlers
_ "github.com/spiral/roadrunner/cmd/rr/http"
)
func main() {
- rr.Logger.Formatter = &logrus.TextFormatter{ForceColors: true}
-
- rr.Container.Register(env.ID, env.NewService(map[string]string{"rr": rr.Version}))
-
+ rr.Container.Register(env.ID, &env.Service{})
rr.Container.Register(rpc.ID, &rpc.Service{})
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()
}