Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.
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
34 changes: 34 additions & 0 deletions commands/completion/functions.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package completion

import (
"encoding/json"

"github.com/docker/model-cli/desktop"
"github.com/spf13/cobra"
)

func NoComplete(_ *cobra.Command, _ []string, _ string) ([]string, cobra.ShellCompDirective) {
return nil, cobra.ShellCompDirectiveNoFileComp
}

// ModelNames offers completion for models present within the local store.
func ModelNames(desktopClient *desktop.Client, limit int) cobra.CompletionFunc {
return func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if limit > 0 && len(args) >= limit {
return nil, cobra.ShellCompDirectiveNoFileComp
}
modelsString, err := desktopClient.List(true, false, false, "")
if err != nil {
return nil, cobra.ShellCompDirectiveError
}
var models []desktop.Model
if err := json.Unmarshal([]byte(modelsString), &models); err != nil {
return nil, cobra.ShellCompDirectiveError
}
var names []string
for _, m := range models {
names = append(names, m.Tags...)
}
return names, cobra.ShellCompDirectiveNoFileComp
}
}
2 changes: 2 additions & 0 deletions commands/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"

"github.com/docker/model-cli/commands/completion"
"github.com/docker/model-cli/desktop"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -32,6 +33,7 @@ func newInspectCmd(desktopClient *desktop.Client) *cobra.Command {
cmd.Println(model)
return nil
},
ValidArgsFunction: completion.ModelNames(desktopClient, 1),
}
c.Flags().BoolVar(&openai, "openai", false, "List model in an OpenAI format")
return c
Expand Down
2 changes: 2 additions & 0 deletions commands/list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package commands

import (
"github.com/docker/model-cli/commands/completion"
"github.com/docker/model-cli/desktop"
"github.com/spf13/cobra"
)
Expand All @@ -20,6 +21,7 @@ func newListCmd(desktopClient *desktop.Client) *cobra.Command {
cmd.Print(models)
return nil
},
ValidArgsFunction: completion.NoComplete,
}
c.Flags().BoolVar(&jsonFormat, "json", false, "List models in a JSON format")
c.Flags().BoolVar(&openai, "openai", false, "List models in an OpenAI format")
Expand Down
2 changes: 2 additions & 0 deletions commands/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"

"github.com/docker/model-cli/commands/completion"
"github.com/docker/model-cli/desktop"
"github.com/spf13/cobra"
)
Expand All @@ -24,6 +25,7 @@ func newPullCmd(desktopClient *desktop.Client) *cobra.Command {
RunE: func(cmd *cobra.Command, args []string) error {
return pullModel(cmd, desktopClient, args[0])
},
ValidArgsFunction: completion.NoComplete,
}
return c
}
Expand Down
2 changes: 2 additions & 0 deletions commands/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package commands
import (
"fmt"

"github.com/docker/model-cli/commands/completion"
"github.com/docker/model-cli/desktop"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -32,6 +33,7 @@ func newRemoveCmd(desktopClient *desktop.Client) *cobra.Command {
}
return nil
},
ValidArgsFunction: completion.ModelNames(desktopClient, -1),
}
return c
}
4 changes: 3 additions & 1 deletion commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strings"

"github.com/docker/model-cli/commands/completion"
"github.com/docker/model-cli/desktop"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -81,6 +82,7 @@ func newRunCmd(desktopClient *desktop.Client) *cobra.Command {
}
return nil
},
ValidArgsFunction: completion.ModelNames(desktopClient, 1),
}
c.Args = func(cmd *cobra.Command, args []string) error {
if len(args) < 1 {
Expand All @@ -90,7 +92,7 @@ func newRunCmd(desktopClient *desktop.Client) *cobra.Command {
"See 'docker model run --help' for more information",
)
}
if len(args) > 2 {
if len(args) >= 2 {
return fmt.Errorf("too many arguments, expected " + cmdArgs)
}
return nil
Expand Down
2 changes: 2 additions & 0 deletions commands/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"os"

"github.com/docker/cli/cli-plugins/hooks"
"github.com/docker/model-cli/commands/completion"
"github.com/docker/model-cli/desktop"
"github.com/spf13/cobra"
)
Expand All @@ -27,6 +28,7 @@ func newStatusCmd(desktopClient *desktop.Client) *cobra.Command {

return nil
},
ValidArgsFunction: completion.NoComplete,
}
return c
}
Expand Down
6 changes: 5 additions & 1 deletion commands/version.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package commands

import "github.com/spf13/cobra"
import (
"github.com/docker/model-cli/commands/completion"
"github.com/spf13/cobra"
)

var Version = "dev"

Expand All @@ -11,6 +14,7 @@ func newVersionCmd() *cobra.Command {
Run: func(cmd *cobra.Command, args []string) {
cmd.Printf("Docker Model Runner version %s\n", Version)
},
ValidArgsFunction: completion.NoComplete,
}
return c
}