summaryrefslogtreecommitdiff
path: root/cmd/rr/utils
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/rr/utils')
-rw-r--r--cmd/rr/utils/config.go23
-rw-r--r--cmd/rr/utils/cprint.go32
-rw-r--r--cmd/rr/utils/verbose.go18
3 files changed, 73 insertions, 0 deletions
diff --git a/cmd/rr/utils/config.go b/cmd/rr/utils/config.go
new file mode 100644
index 00000000..e7e22b3a
--- /dev/null
+++ b/cmd/rr/utils/config.go
@@ -0,0 +1,23 @@
+package utils
+
+import (
+ "github.com/spf13/viper"
+ "github.com/spiral/roadrunner/service"
+)
+
+type ConfigWrapper struct {
+ Viper *viper.Viper
+}
+
+func (w *ConfigWrapper) Get(key string) service.Config {
+ sub := w.Viper.Sub(key)
+ if sub == nil {
+ return nil
+ }
+
+ return &ConfigWrapper{sub}
+}
+
+func (w *ConfigWrapper) Unmarshal(out interface{}) error {
+ return w.Viper.Unmarshal(out)
+}
diff --git a/cmd/rr/utils/cprint.go b/cmd/rr/utils/cprint.go
new file mode 100644
index 00000000..f6f828f8
--- /dev/null
+++ b/cmd/rr/utils/cprint.go
@@ -0,0 +1,32 @@
+package utils
+
+import (
+ "fmt"
+ "gopkg.in/AlecAivazis/survey.v1/core"
+ "regexp"
+ "strings"
+)
+
+// Printf works identically to fmt.Print but adds `<white+hb>color formatting support for CLI</reset>`.
+func Printf(format string, args ...interface{}) {
+ fmt.Print(Sprintf(format, args...))
+}
+
+// Sprintf works identically to fmt.Sprintf but adds `<white+hb>color formatting support for CLI</reset>`.
+func Sprintf(format string, args ...interface{}) string {
+ r, err := regexp.Compile(`<([^>]+)>`)
+ if err != nil {
+ panic(err)
+ }
+
+ format = r.ReplaceAllStringFunc(format, func(s string) string {
+ return fmt.Sprintf(`{{color "%s"}}`, strings.Trim(s, "<>/"))
+ })
+
+ out, err := core.RunTemplate(fmt.Sprintf(format, args...), nil)
+ if err != nil {
+ panic(err)
+ }
+
+ return out
+}
diff --git a/cmd/rr/utils/verbose.go b/cmd/rr/utils/verbose.go
new file mode 100644
index 00000000..43770f34
--- /dev/null
+++ b/cmd/rr/utils/verbose.go
@@ -0,0 +1,18 @@
+package utils
+
+//if f.Verbose {
+// rr.Observe(func(event int, ctx interface{}) {
+// switch event {
+// case roadrunner.EventPoolError:
+// logrus.Error(ctx)
+// case roadrunner.EventWorkerCreate:
+// logrus.Infof("%s - created", ctx)
+// case roadrunner.EventWorkerError:
+// logrus.Errorf("%s: %s", ctx.(roadrunner.WorkerError).Worker, ctx.(roadrunner.WorkerError).Error())
+// case roadrunner.EventWorkerDestruct:
+// logrus.Warnf("%s - destructed", ctx)
+// case roadrunner.EventWorkerKill:
+// logrus.Warnf("%s - killed", ctx)
+// }
+// })
+//}