diff options
author | Valery Piashchynski <[email protected]> | 2022-03-06 12:13:02 +0100 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2022-03-06 12:13:02 +0100 |
commit | 70e4f020afd0352dc52114651f0f65c1965ed399 (patch) | |
tree | cc6595214e4ff39600099fb8c6f39e7a3dd560e9 /internal/cli/serve | |
parent | 587702be62b65c151d27dc79e62fcbbd11290e6f (diff) |
remove config plugin usage from the root
Signed-off-by: Valery Piashchynski <[email protected]>
Diffstat (limited to 'internal/cli/serve')
-rw-r--r-- | internal/cli/serve/command.go | 28 | ||||
-rw-r--r-- | internal/cli/serve/command_test.go | 11 |
2 files changed, 30 insertions, 9 deletions
diff --git a/internal/cli/serve/command.go b/internal/cli/serve/command.go index a0ce36db..559868d5 100644 --- a/internal/cli/serve/command.go +++ b/internal/cli/serve/command.go @@ -14,23 +14,35 @@ import ( "github.com/spf13/cobra" ) +const ( + rrPrefix string = "rr" +) + // NewCommand creates `serve` command. -func NewCommand(cfgPlugin *configImpl.Plugin) *cobra.Command { //nolint:funlen +func NewCommand(override *[]string, cfgFile *string, silent *bool) *cobra.Command { //nolint:funlen,gocognit return &cobra.Command{ Use: "serve", Short: "Start RoadRunner server", RunE: func(*cobra.Command, []string) error { const op = errors.Op("handle_serve_command") + // just to be safe + if cfgFile == nil { + return errors.E(op, errors.Str("no configuration file provided")) + } // create endure container config - containerCfg, err := container.NewConfig(cfgPlugin) + containerCfg, err := container.NewConfig(*cfgFile) if err != nil { return errors.E(op, err) } - // set the grace period which would be same for all the plugins - cfgPlugin.Timeout = containerCfg.GracePeriod - cfgPlugin.Version = meta.Version() + cfg := &configImpl.Plugin{ + Path: *cfgFile, + Prefix: rrPrefix, + Timeout: containerCfg.GracePeriod, + Flags: *override, + Version: meta.Version(), + } // create endure container endureContainer, err := container.NewContainer(*containerCfg) @@ -39,7 +51,7 @@ func NewCommand(cfgPlugin *configImpl.Plugin) *cobra.Command { //nolint:funlen } // register config plugin - if err = endureContainer.Register(cfgPlugin); err != nil { + if err = endureContainer.Register(cfg); err != nil { return errors.E(op, err) } @@ -77,7 +89,9 @@ func NewCommand(cfgPlugin *configImpl.Plugin) *cobra.Command { //nolint:funlen os.Exit(1) }() - fmt.Printf("[INFO] RoadRunner server started; version: %s, buildtime: %s\n", meta.Version(), meta.BuildTime()) + if !*silent { + fmt.Printf("[INFO] RoadRunner server started; version: %s, buildtime: %s\n", meta.Version(), meta.BuildTime()) + } for { select { diff --git a/internal/cli/serve/command_test.go b/internal/cli/serve/command_test.go index 8aef0ff7..4c8c6128 100644 --- a/internal/cli/serve/command_test.go +++ b/internal/cli/serve/command_test.go @@ -5,12 +5,19 @@ import ( "github.com/roadrunner-server/roadrunner/v2/internal/cli/serve" - "github.com/roadrunner-server/config/v2" "github.com/stretchr/testify/assert" ) func TestCommandProperties(t *testing.T) { - cmd := serve.NewCommand(&config.Plugin{}) + path := "" + cmd := serve.NewCommand(nil, &path, nil) + + assert.Equal(t, "serve", cmd.Use) + assert.NotNil(t, cmd.RunE) +} + +func TestCommandNil(t *testing.T) { + cmd := serve.NewCommand(nil, nil, nil) assert.Equal(t, "serve", cmd.Use) assert.NotNil(t, cmd.RunE) |