cmd: add server version
This commit is contained in:
parent
0db4706ec2
commit
0f0cd265a7
1 changed files with 26 additions and 1 deletions
27
cmd/cmd.go
27
cmd/cmd.go
|
@ -1037,8 +1037,25 @@ func checkServerHeartbeat(cmd *cobra.Command, _ []string) error {
|
||||||
return nil
|
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 {
|
func NewCLI() *cobra.Command {
|
||||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||||
|
cobra.EnableCommandSorting = false
|
||||||
|
|
||||||
rootCmd := &cobra.Command{
|
rootCmd := &cobra.Command{
|
||||||
Use: "ollama",
|
Use: "ollama",
|
||||||
|
@ -1049,9 +1066,17 @@ func NewCLI() *cobra.Command {
|
||||||
DisableDefaultCmd: true,
|
DisableDefaultCmd: true,
|
||||||
},
|
},
|
||||||
Version: version.Version,
|
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{
|
createCmd := &cobra.Command{
|
||||||
Use: "create MODEL",
|
Use: "create MODEL",
|
||||||
|
|
Loading…
Reference in a new issue