Skip to content

Commit 7982268

Browse files
committed
Move code closer to where it's used
Signed-off-by: David Gageot <[email protected]>
1 parent 7f5a138 commit 7982268

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

cmd/docker-mcp/command.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"github.com/docker/cli/cli-plugins/plugin"
12+
"github.com/docker/cli/cli/command"
1213
"github.com/spf13/cobra"
1314

1415
"github.com/docker/mcp-gateway/cmd/docker-mcp/backup"
@@ -43,7 +44,7 @@ Examples:
4344
`
4445

4546
// rootCommand returns the root command for the init plugin
46-
func rootCommand(ctx context.Context, cwd string, docker docker.Client) *cobra.Command {
47+
func rootCommand(ctx context.Context, cwd string, dockerCli command.Cli) *cobra.Command {
4748
cmd := &cobra.Command{
4849
Use: "mcp [OPTIONS]",
4950
TraverseChildren: true,
@@ -74,15 +75,17 @@ func rootCommand(ctx context.Context, cwd string, docker docker.Client) *cobra.C
7475
return []string{"--help"}, cobra.ShellCompDirectiveNoFileComp
7576
})
7677

77-
cmd.AddCommand(secret.NewSecretsCmd(docker))
78+
dockerClient := docker.NewClient(dockerCli)
79+
80+
cmd.AddCommand(secret.NewSecretsCmd(dockerClient))
7881
cmd.AddCommand(policy.NewPolicyCmd())
7982
cmd.AddCommand(oauth.NewOAuthCmd())
8083
cmd.AddCommand(client.NewClientCmd(cwd))
8184
cmd.AddCommand(catalog.NewCatalogCmd())
8285
cmd.AddCommand(versionCommand())
83-
cmd.AddCommand(gatewayCommand(docker))
84-
cmd.AddCommand(configCommand(docker))
85-
cmd.AddCommand(serverCommand(docker))
86+
cmd.AddCommand(gatewayCommand(dockerClient))
87+
cmd.AddCommand(configCommand(dockerClient))
88+
cmd.AddCommand(serverCommand(dockerClient))
8689
cmd.AddCommand(toolsCommand())
8790

8891
if os.Getenv("DOCKER_MCP_SHOW_HIDDEN") == "1" {

cmd/docker-mcp/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"github.com/docker/cli/cli/command"
1313
"github.com/spf13/cobra"
1414

15-
"github.com/docker/mcp-gateway/cmd/docker-mcp/internal/docker"
1615
"github.com/docker/mcp-gateway/cmd/docker-mcp/version"
1716
)
1817

@@ -31,8 +30,7 @@ func main() {
3130
}
3231

3332
plugin.Run(func(dockerCli command.Cli) *cobra.Command {
34-
dockerClient := docker.NewClient(dockerCli)
35-
return rootCommand(ctx, cwd, dockerClient)
33+
return rootCommand(ctx, cwd, dockerCli)
3634
},
3735
manager.Metadata{
3836
SchemaVersion: "0.1.0",

0 commit comments

Comments
 (0)