Skip to content

Commit cf8b319

Browse files
committed
lint
1 parent 0f5c6c5 commit cf8b319

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

cmd/ftl/cmd_mcp.go

+21-12
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ func newMCPServer(ctx context.Context, k *kong.Kong, projectConfig projectconfig
7474
), func(serverCtx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
7575
return statusTool(ctx, buildEngineClient, adminClient)
7676
})
77-
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "NewModule", []string{"module", "new"}, IncludeOptional("dir"), Pattern("name", optional.Some(moduleRegex))))
78-
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "CallVerb", []string{"call"}, IncludeOptional("request")))
77+
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "NewModule", []string{"module", "new"}, includeOptional("dir"), pattern("name", optional.Some(moduleRegex))))
78+
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "CallVerb", []string{"call"}, includeOptional("request")))
7979
// all secret commands, with xor group of bools for providers
8080
// all config commands, with xor group of bools for providers
8181
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "ResetSubscription", []string{"pubsub", "subscription", "reset"}))
82-
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "NewMySQLDatabase", []string{"mysql", "new"}, Pattern("datasource", optional.Some(refRegex))))
83-
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "NewMySQLMigration", []string{"mysql", "new", "migration"}, Ignore(newSQLCmd{}, "datasource")))
82+
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "NewMySQLDatabase", []string{"mysql", "new"}, pattern("datasource", optional.Some(refRegex))))
83+
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "NewMySQLMigration", []string{"mysql", "new", "migration"}, ignore(newSQLCmd{}, "datasource")))
8484
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "NewPostgresDatabase", []string{"postgres", "new"}))
85-
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "NewPostgresMigration", []string{"postgres", "new", "migration"}, Ignore(newSQLCmd{}, "datasource")))
85+
addTool(toolFromCLI(ctx, k, projectConfig, bindContext, "NewPostgresMigration", []string{"postgres", "new", "migration"}, ignore(newSQLCmd{}, "datasource")))
8686
return s
8787
}
8888

@@ -202,7 +202,7 @@ func commentForPath(pos schema.Position, modulePath string) (string, error) {
202202

203203
type cliToolOption func(inputOptions *cliConfig)
204204

205-
func IncludeOptional(name string) cliToolOption {
205+
func includeOptional(name string) cliToolOption {
206206
return func(inputOptions *cliConfig) {
207207
o, ok := inputOptions.InputOptions[name]
208208
if !ok {
@@ -213,7 +213,7 @@ func IncludeOptional(name string) cliToolOption {
213213
}
214214
}
215215

216-
func Pattern(name string, pattern optional.Option[string]) cliToolOption {
216+
func pattern(name string, pattern optional.Option[string]) cliToolOption {
217217
return func(inputOptions *cliConfig) {
218218
o, ok := inputOptions.InputOptions[name]
219219
if !ok {
@@ -224,7 +224,7 @@ func Pattern(name string, pattern optional.Option[string]) cliToolOption {
224224
}
225225
}
226226

227-
func Ignore(model any, name string) cliToolOption {
227+
func ignore(model any, name string) cliToolOption {
228228
return func(inputOptions *cliConfig) {
229229
o, ok := inputOptions.InputOptions[name]
230230
if !ok {
@@ -329,7 +329,7 @@ func toolFromCLI(ctx context.Context, k *kong.Kong, projectConfig projectconfig.
329329
// validate that all configured options were found
330330
for name := range config.InputOptions {
331331
if !included[name] {
332-
panic(fmt.Sprintf("ftl %v: could not find option %q in:\n%v", strings.Join(cmdPath, " "), name, strings.Join(slices.Map(maps.Keys(all), func(name string) string {
332+
panic(fmt.Sprintf("ftl %v: could not find option %q in:\n%v", strings.Join(cmdPath, " "), name, strings.Join(slices.Map(maps.Keys(all), func(name string) string { //nolint: exptostd
333333
if included[name] {
334334
return name
335335
}
@@ -407,7 +407,11 @@ func optionForInput(value *kong.Value, description string, flag bool, config *op
407407
panic("unhandled bool argument")
408408
}
409409
if value.HasDefault {
410-
opts = append(opts, mcp.DefaultBool(value.DefaultValue.Interface().(bool)))
410+
defaultValue, ok := value.DefaultValue.Interface().(bool)
411+
if !ok {
412+
panic("expected default value to be a bool")
413+
}
414+
opts = append(opts, mcp.DefaultBool(defaultValue))
411415
}
412416
return mcp.WithBoolean(name, opts...), func(args map[string]any) ([]string, error) {
413417
anyValue, ok := args[name]
@@ -425,7 +429,11 @@ func optionForInput(value *kong.Value, description string, flag bool, config *op
425429

426430
case reflect.String:
427431
if value.HasDefault {
428-
opts = append(opts, mcp.DefaultString(value.DefaultValue.Interface().(string)))
432+
defaultValue, ok := value.DefaultValue.Interface().(string)
433+
if !ok {
434+
panic("expected default value to be a string")
435+
}
436+
opts = append(opts, mcp.DefaultString(defaultValue))
429437
}
430438
return newStringOption(name, flag, opts)
431439
case reflect.Struct:
@@ -434,8 +442,9 @@ func optionForInput(value *kong.Value, description string, flag bool, config *op
434442
opts = append(opts, mcp.Pattern(refRegex))
435443
return newStringOption(name, flag, opts)
436444
}
437-
}
438445

446+
default:
447+
}
439448
panic(fmt.Sprintf("implement type %v %v for %s (hasDefault = %v)", value.Target.Type(), value.Target.Kind(), name, value.HasDefault))
440449
}
441450

cmd/ftl/cmd_mcp_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313
func TestMCPServerCreation(t *testing.T) {
1414
t.Parallel()
1515

16-
ctx := log.ContextWithNewDefaultLogger(context.Background())
16+
ctx := log.ContextWithNewDefaultLogger(t.Context())
1717
csm := &currentStatusManager{}
1818
k := createKongApplication(&cli, csm)
1919
assert.NotPanics(t, func() {

cmd/ftl/inner_cmd.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"context"
5+
"fmt"
56
"syscall"
67

78
"github.com/alecthomas/kong"
@@ -39,18 +40,18 @@ func runInnerCmd(ctx context.Context, k *kong.Kong, projConfig projectconfig.Con
3940
// Dynamically update the kong app with language specific flags for the "ftl module new" command.
4041
languagePlugin, err := languageplugin.PrepareNewCmd(ctx, projConfig, k, args)
4142
if err != nil {
42-
return err
43+
return fmt.Errorf("could not prepare for command: %w", err)
4344
}
4445
kctx, err := k.Parse(args)
4546
if err != nil {
46-
return err
47+
return err //nolint:wrapcheck
4748
}
4849
kctx.Bind(languagePlugin)
4950
subctx := binder(ctx, kctx)
5051

5152
err = kctx.Run(subctx)
5253
if err != nil {
53-
return err
54+
return err //no:lint:wrapcheck
5455
}
5556
return nil
5657
}

0 commit comments

Comments
 (0)