Skip to content

Commit cd9cc87

Browse files
authored
[minor] align all sitectl features in a coherent SDK (#12)
1 parent 4776470 commit cd9cc87

7 files changed

Lines changed: 23 additions & 200 deletions

File tree

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build deps lint test work install docs-snippets
1+
.PHONY: build deps lint test work install
22

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

32-
docs-snippets: work
33-
go run ./scripts/gen-docs-snippets/

cmd/extensions.go

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
)
2222

2323
var drupalComponentName string
24-
var drupalRootfsPath string
2524

2625
const (
2726
cachePageWarningThreshold = int64(1 << 30)
@@ -148,18 +147,17 @@ var componentExtensionSetCmd = &cobra.Command{
148147
},
149148
}
150149

151-
var debugExtensionCmd = &cobra.Command{
152-
Use: "__debug",
153-
Short: "Internal debug extension command",
154-
Hidden: true,
155-
RunE: func(cmd *cobra.Command, args []string) error {
156-
rendered, err := renderDrupalDebug(cmd.Context())
157-
if err != nil {
158-
return err
159-
}
160-
_, err = fmt.Fprintln(cmd.OutOrStdout(), rendered)
161-
return err
162-
},
150+
// drupalDebugRunner implements plugin.DebugRunner for the drupal plugin.
151+
type drupalDebugRunner struct {
152+
rootfsPath string
153+
}
154+
155+
func (r *drupalDebugRunner) BindFlags(cmd *cobra.Command) {
156+
cmd.Flags().StringVar(&r.rootfsPath, "drupal-rootfs", "", "Drupal rootfs path override")
157+
}
158+
159+
func (r *drupalDebugRunner) Render(cmd *cobra.Command, ctx *config.Context) (string, error) {
160+
return renderDrupalDebugBody(cmd.Context(), ctx, r.rootfsPath)
163161
}
164162

165163
func init() {
@@ -169,19 +167,13 @@ func init() {
169167
componentExtensionCmd.AddCommand(componentExtensionDescribeCmd)
170168
componentExtensionCmd.AddCommand(componentExtensionReconcileCmd)
171169
componentExtensionCmd.AddCommand(componentExtensionSetCmd)
172-
173-
debugExtensionCmd.Flags().StringVar(&drupalRootfsPath, "drupal-rootfs", "", "Drupal rootfs path override")
174170
}
175171

176-
func renderDrupalDebug(runCtx context.Context) (string, error) {
172+
func renderDrupalDebugBody(runCtx context.Context, ctx *config.Context, rootfsOverride string) (string, error) {
177173
slog.Debug("starting plugin debug", "plugin", "drupal")
178174
if sdk == nil {
179175
return "", fmt.Errorf("plugin sdk is not initialized")
180176
}
181-
ctx, err := sdk.GetContext()
182-
if err != nil {
183-
return "", err
184-
}
185177
slog.Debug("resolved plugin context", "plugin", "drupal", "context", ctx.Name, "project_dir", ctx.ProjectDir)
186178
slog.Debug("creating file accessor", "plugin", "drupal")
187179
files, err := sdk.GetFileAccessor()
@@ -190,7 +182,7 @@ func renderDrupalDebug(runCtx context.Context) (string, error) {
190182
}
191183
defer files.Close()
192184

193-
rootfs := strings.TrimSpace(drupalRootfsPath)
185+
rootfs := strings.TrimSpace(rootfsOverride)
194186
if rootfs == "" {
195187
rootfs = ctx.EffectiveDrupalRootfs()
196188
}
@@ -262,8 +254,8 @@ func renderDrupalDebug(runCtx context.Context) (string, error) {
262254
}
263255
body = append(body, "", strings.Join(patchLines, "\n"))
264256

265-
slog.Debug("finished plugin debug", "plugin", "drupal")
266-
return debugui.RenderPanel("drupal", strings.Join(body, "\n")), nil
257+
slog.Debug("finished plugin debug body", "plugin", "drupal")
258+
return strings.Join(body, "\n"), nil
267259
}
268260

269261
func renderCachePageSummary(runCtx context.Context) (string, error) {

cmd/extensions_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ func TestRenderDrupalDebugRequiresSDK(t *testing.T) {
196196
sdk = nil
197197
defer func() { sdk = original }()
198198

199-
_, err := renderDrupalDebug(context.Background())
199+
_, err := renderDrupalDebugBody(context.Background(), &config.Context{}, "")
200200
if err == nil {
201-
t.Fatal("expected renderDrupalDebug() error")
201+
t.Fatal("expected renderDrupalDebugBody() error")
202202
}
203203
if !strings.Contains(err.Error(), "plugin sdk is not initialized") {
204204
t.Fatalf("unexpected error: %v", err)

cmd/root.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func RegisterCommands(s *plugin.SDK) {
2121
sdk.AddCommand(sdk.GetDiscoveryMetadataCommand())
2222
sdk.AddCommand(componentExtensionCmd)
2323
sdk.RegisterCreateRunner(createDefinition(), createRunner{})
24-
sdk.AddCommand(debugExtensionCmd)
24+
sdk.RegisterDebugHandler(&drupalDebugRunner{})
2525
sdk.AddCommand(drushCmd)
2626
sdk.AddCommand(loginCmd)
2727
sdk.AddCommand(syncCmd)

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ module github.com/libops/sitectl-drupal
33
go 1.25.8
44

55
require (
6-
github.com/libops/sitectl v0.15.0
6+
github.com/libops/sitectl v0.16.0
77
github.com/spf13/cobra v1.10.2
8-
github.com/spf13/pflag v1.0.10
98
gopkg.in/yaml.v3 v3.0.1
109
)
1110

@@ -56,6 +55,7 @@ require (
5655
github.com/pkg/sftp v1.13.10 // indirect
5756
github.com/rivo/uniseg v0.4.7 // indirect
5857
github.com/sahilm/fuzzy v0.1.1 // indirect
58+
github.com/spf13/pflag v1.0.10 // indirect
5959
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
6060
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
6161
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.64.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
8282
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
8383
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
8484
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
85-
github.com/libops/sitectl v0.15.0 h1:YZrBcpvY3fAZlLeCFs9OndDHiam7l9nABy2hDpUllSI=
86-
github.com/libops/sitectl v0.15.0/go.mod h1:Q4mIOPKbV1CJAYJ/x0e+ZxKQ2M/zOrqiWE7YmL5kaH4=
85+
github.com/libops/sitectl v0.16.0 h1:Ayx/X9aEv2dbu4rQPVPVsyFlw0zJJ1+V9IArdwD6jUE=
86+
github.com/libops/sitectl v0.16.0/go.mod h1:Q4mIOPKbV1CJAYJ/x0e+ZxKQ2M/zOrqiWE7YmL5kaH4=
8787
github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag=
8888
github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
8989
github.com/mattn/go-runewidth v0.0.20 h1:WcT52H91ZUAwy8+HUkdM3THM6gXqXuLJi9O3rjcQQaQ=

scripts/gen-docs-snippets/main.go

Lines changed: 0 additions & 167 deletions
This file was deleted.

0 commit comments

Comments
 (0)