Skip to content

Get up and running with Kimi, GLM, MiniMax, DeepSeek, gpt-oss, Qwen, Gemma and other models.

cmd: add server version

Michael Yang0f0cd265a7a4
diff --git a/cmd/cmd.go b/cmd/cmd.go
index 073b1b4aa..2fd5cacc8 100644
--- a/cmd/cmd.go
+++ b/cmd/cmd.go
@@ -1037,8 +1037,25 @@ func checkServerHeartbeat(cmd *cobra.Command, _ []string) error {
return nil
}
+func versionHandler(cmd *cobra.Command, _ []string) {
+ fmt.Printf("ollama version %s\n", version.Version)
+
+ client, err := api.ClientFromEnvironment()
+ if err != nil {
+ return
+ }
+
+ serverVersion, err := client.Version(cmd.Context())
+ if err != nil {
+ return
+ }
+
+ fmt.Printf("server version %s\n", serverVersion)
+}
+
func NewCLI() *cobra.Command {
log.SetFlags(log.LstdFlags | log.Lshortfile)
+ cobra.EnableCommandSorting = false
rootCmd := &cobra.Command{
Use: "ollama",
@@ -1049,9 +1066,17 @@ func NewCLI() *cobra.Command {
DisableDefaultCmd: true,
},
Version: version.Version,
+ Run: func(cmd *cobra.Command, args []string) {
+ if version, _ := cmd.Flags().GetBool("version"); version {
+ versionHandler(cmd, args)
+ return
+ }
+
+ cmd.Print(cmd.UsageString())
+ },
}
- cobra.EnableCommandSorting = false
+ rootCmd.Flags().BoolP("version", "v", false, "Show version information")
createCmd := &cobra.Command{
Use: "create MODEL",