Skip to content
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
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build deps lint test work install docs-snippets
.PHONY: build deps lint test work install

BINARY_NAME=sitectl-drupal
INSTALL_DIR ?= $(or $(dir $(shell which $(BINARY_NAME) 2>/dev/null)),/usr/local/bin/)
Expand Down Expand Up @@ -29,5 +29,3 @@ test: build
work:
./scripts/use-go-work.sh

docs-snippets: work
go run ./scripts/gen-docs-snippets/
38 changes: 15 additions & 23 deletions cmd/extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
)

var drupalComponentName string
var drupalRootfsPath string

const (
cachePageWarningThreshold = int64(1 << 30)
Expand Down Expand Up @@ -148,18 +147,17 @@ var componentExtensionSetCmd = &cobra.Command{
},
}

var debugExtensionCmd = &cobra.Command{
Use: "__debug",
Short: "Internal debug extension command",
Hidden: true,
RunE: func(cmd *cobra.Command, args []string) error {
rendered, err := renderDrupalDebug(cmd.Context())
if err != nil {
return err
}
_, err = fmt.Fprintln(cmd.OutOrStdout(), rendered)
return err
},
// drupalDebugRunner implements plugin.DebugRunner for the drupal plugin.
type drupalDebugRunner struct {
rootfsPath string
}

func (r *drupalDebugRunner) BindFlags(cmd *cobra.Command) {
cmd.Flags().StringVar(&r.rootfsPath, "drupal-rootfs", "", "Drupal rootfs path override")
}

func (r *drupalDebugRunner) Render(cmd *cobra.Command, ctx *config.Context) (string, error) {
return renderDrupalDebugBody(cmd.Context(), ctx, r.rootfsPath)
}

func init() {
Expand All @@ -169,19 +167,13 @@ func init() {
componentExtensionCmd.AddCommand(componentExtensionDescribeCmd)
componentExtensionCmd.AddCommand(componentExtensionReconcileCmd)
componentExtensionCmd.AddCommand(componentExtensionSetCmd)

debugExtensionCmd.Flags().StringVar(&drupalRootfsPath, "drupal-rootfs", "", "Drupal rootfs path override")
}

func renderDrupalDebug(runCtx context.Context) (string, error) {
func renderDrupalDebugBody(runCtx context.Context, ctx *config.Context, rootfsOverride string) (string, error) {
slog.Debug("starting plugin debug", "plugin", "drupal")
if sdk == nil {
return "", fmt.Errorf("plugin sdk is not initialized")
}
ctx, err := sdk.GetContext()
if err != nil {
return "", err
}
slog.Debug("resolved plugin context", "plugin", "drupal", "context", ctx.Name, "project_dir", ctx.ProjectDir)
slog.Debug("creating file accessor", "plugin", "drupal")
files, err := sdk.GetFileAccessor()
Expand All @@ -190,7 +182,7 @@ func renderDrupalDebug(runCtx context.Context) (string, error) {
}
defer files.Close()

rootfs := strings.TrimSpace(drupalRootfsPath)
rootfs := strings.TrimSpace(rootfsOverride)
if rootfs == "" {
rootfs = ctx.EffectiveDrupalRootfs()
}
Expand Down Expand Up @@ -262,8 +254,8 @@ func renderDrupalDebug(runCtx context.Context) (string, error) {
}
body = append(body, "", strings.Join(patchLines, "\n"))

slog.Debug("finished plugin debug", "plugin", "drupal")
return debugui.RenderPanel("drupal", strings.Join(body, "\n")), nil
slog.Debug("finished plugin debug body", "plugin", "drupal")
return strings.Join(body, "\n"), nil
}

func renderCachePageSummary(runCtx context.Context) (string, error) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/extensions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,9 @@ func TestRenderDrupalDebugRequiresSDK(t *testing.T) {
sdk = nil
defer func() { sdk = original }()

_, err := renderDrupalDebug(context.Background())
_, err := renderDrupalDebugBody(context.Background(), &config.Context{}, "")
if err == nil {
t.Fatal("expected renderDrupalDebug() error")
t.Fatal("expected renderDrupalDebugBody() error")
}
if !strings.Contains(err.Error(), "plugin sdk is not initialized") {
t.Fatalf("unexpected error: %v", err)
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func RegisterCommands(s *plugin.SDK) {
sdk.AddCommand(sdk.GetDiscoveryMetadataCommand())
sdk.AddCommand(componentExtensionCmd)
sdk.RegisterCreateRunner(createDefinition(), createRunner{})
sdk.AddCommand(debugExtensionCmd)
sdk.RegisterDebugHandler(&drupalDebugRunner{})
sdk.AddCommand(drushCmd)
sdk.AddCommand(loginCmd)
sdk.AddCommand(syncCmd)
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ module github.com/libops/sitectl-drupal
go 1.25.8

require (
github.com/libops/sitectl v0.15.0
github.com/libops/sitectl v0.16.0
github.com/spf13/cobra v1.10.2
github.com/spf13/pflag v1.0.10
gopkg.in/yaml.v3 v3.0.1
)

Expand Down Expand Up @@ -56,6 +55,7 @@ require (
github.com/pkg/sftp v1.13.10 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sahilm/fuzzy v0.1.1 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/libops/sitectl v0.15.0 h1:YZrBcpvY3fAZlLeCFs9OndDHiam7l9nABy2hDpUllSI=
github.com/libops/sitectl v0.15.0/go.mod h1:Q4mIOPKbV1CJAYJ/x0e+ZxKQ2M/zOrqiWE7YmL5kaH4=
github.com/libops/sitectl v0.16.0 h1:Ayx/X9aEv2dbu4rQPVPVsyFlw0zJJ1+V9IArdwD6jUE=
github.com/libops/sitectl v0.16.0/go.mod h1:Q4mIOPKbV1CJAYJ/x0e+ZxKQ2M/zOrqiWE7YmL5kaH4=
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.20 h1:WcT52H91ZUAwy8+HUkdM3THM6gXqXuLJi9O3rjcQQaQ=
Expand Down
167 changes: 0 additions & 167 deletions scripts/gen-docs-snippets/main.go

This file was deleted.