From 698c58ee36f2e034eaf3b8e0a9a6600e59426329 Mon Sep 17 00:00:00 2001 From: Dorin Geman Date: Thu, 15 Jan 2026 18:42:08 +0200 Subject: [PATCH 1/2] feat(cli/bench): add shell completion Signed-off-by: Dorin Geman --- cmd/cli/commands/bench.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/cli/commands/bench.go b/cmd/cli/commands/bench.go index c8b9a546..4cc2d910 100644 --- a/cmd/cli/commands/bench.go +++ b/cmd/cli/commands/bench.go @@ -13,6 +13,7 @@ import ( "sync" "time" + "github.com/docker/model-runner/cmd/cli/commands/completion" "github.com/docker/model-runner/cmd/cli/desktop" "github.com/docker/model-runner/pkg/inference" "github.com/spf13/cobra" @@ -63,7 +64,8 @@ func newBenchCmd() *cobra.Command { This command runs a series of benchmarks with 1, 2, 4, and 8 concurrent requests by default, measuring the tokens per second (TPS) that the model can generate.`, - Args: cobra.ExactArgs(1), + Args: requireExactArgs(1, "bench", "MODEL"), + ValidArgsFunction: completion.ModelNames(getDesktopClient, 1), RunE: func(cmd *cobra.Command, args []string) error { model = args[0] From 707d6a92959f4ca1ca1771697208aaf4111e8c88 Mon Sep 17 00:00:00 2001 From: Dorin Geman Date: Fri, 16 Jan 2026 11:38:26 +0200 Subject: [PATCH 2/2] fix(cli/completion): handle PersistentPreRunE error Signed-off-by: Dorin Geman --- cmd/cli/commands/completion/functions.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/cli/commands/completion/functions.go b/cmd/cli/commands/completion/functions.go index 2930c022..2589ac78 100644 --- a/cmd/cli/commands/completion/functions.go +++ b/cmd/cli/commands/completion/functions.go @@ -17,7 +17,9 @@ func ModelNames(desktopClient func() *desktop.Client, limit int) cobra.Completio // HACK: Invoke rootCmd's PersistentPreRunE, which is needed for context // detection and client initialization. This function isn't invoked // automatically on autocompletion paths. - cmd.Parent().PersistentPreRunE(cmd, args) + if err := cmd.Parent().PersistentPreRunE(cmd, args); err != nil { + return nil, cobra.ShellCompDirectiveError + } if limit > 0 && len(args) >= limit { return nil, cobra.ShellCompDirectiveNoFileComp @@ -41,7 +43,9 @@ func ModelNamesAndTags(desktopClient func() *desktop.Client, limit int) cobra.Co // HACK: Invoke rootCmd's PersistentPreRunE, which is needed for context // detection and client initialization. This function isn't invoked // automatically on autocompletion paths. - cmd.Parent().PersistentPreRunE(cmd, args) + if err := cmd.Parent().PersistentPreRunE(cmd, args); err != nil { + return nil, cobra.ShellCompDirectiveError + } if limit > 0 && len(args) >= limit { return nil, cobra.ShellCompDirectiveNoFileComp