Skip to content

refactor(cli): avoid importing coderd in slim server #9483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/cli/config"
"github.com/coder/coder/v2/coderd"
"github.com/coder/coder/v2/coderd/gitauth"
"github.com/coder/coder/v2/coderd/telemetry"
"github.com/coder/coder/v2/codersdk"
Expand Down Expand Up @@ -119,10 +118,7 @@ func (r *RootCmd) Core() []*clibase.Cmd {
}

func (r *RootCmd) AGPL() []*clibase.Cmd {
all := append(r.Core(), r.Server(func(_ context.Context, o *coderd.Options) (*coderd.API, io.Closer, error) {
api := coderd.New(o)
return api, api, nil
}))
all := append(r.Core(), r.Server( /* Do not import coderd here. */ nil))
return all
}

Expand Down
7 changes: 7 additions & 0 deletions cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,13 @@ func enablePrometheus(
}

func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error)) *clibase.Cmd {
if newAPI == nil {
newAPI = func(_ context.Context, o *coderd.Options) (*coderd.API, io.Closer, error) {
api := coderd.New(o)
return api, api, nil
}
}

var (
vals = new(codersdk.DeploymentValues)
opts = vals.Options()
Expand Down
4 changes: 1 addition & 3 deletions cli/server_slim.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,15 @@
package cli

import (
"context"
"fmt"
"io"
"os"

"github.com/coder/coder/v2/cli/clibase"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/coderd"
)

func (r *RootCmd) Server(_ func(context.Context, *coderd.Options) (*coderd.API, io.Closer, error)) *clibase.Cmd {
func (r *RootCmd) Server(_ func()) *clibase.Cmd {
root := &clibase.Cmd{
Use: "server",
Short: "Start a Coder server",
Expand Down
2 changes: 1 addition & 1 deletion enterprise/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type RootCmd struct {

func (r *RootCmd) enterpriseOnly() []*clibase.Cmd {
return []*clibase.Cmd{
r.server(),
r.Server(nil),
r.workspaceProxy(),
r.features(),
r.licenses(),
Expand Down
4 changes: 2 additions & 2 deletions enterprise/cli/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ import (
agplcoderd "github.com/coder/coder/v2/coderd"
)

func (r *RootCmd) server() *clibase.Cmd {
cmd := r.Server(func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, io.Closer, error) {
func (r *RootCmd) Server(_ func()) *clibase.Cmd {
cmd := r.RootCmd.Server(func(ctx context.Context, options *agplcoderd.Options) (*agplcoderd.API, io.Closer, error) {
if options.DeploymentValues.DERP.Server.RelayURL.String() != "" {
_, err := url.Parse(options.DeploymentValues.DERP.Server.RelayURL.String())
if err != nil {
Expand Down
20 changes: 0 additions & 20 deletions enterprise/cli/server_slim.go

This file was deleted.