Commit 76b85bc0 authored by Michael Yang's avatar Michael Yang
Browse files

set non-zero error code on error

parent 2ab20095
...@@ -75,6 +75,7 @@ func CreateHandler(cmd *cobra.Command, args []string) error { ...@@ -75,6 +75,7 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
spinner = NewSpinner(resp.Status) spinner = NewSpinner(resp.Status)
go spinner.Spin(100 * time.Millisecond) go spinner.Spin(100 * time.Millisecond)
} }
return nil return nil
} }
...@@ -84,6 +85,9 @@ func CreateHandler(cmd *cobra.Command, args []string) error { ...@@ -84,6 +85,9 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
if spinner != nil { if spinner != nil {
spinner.Stop() spinner.Stop()
if spinner.description != "success" {
return errors.New("unexpected end to create model")
}
} }
return nil return nil
...@@ -149,6 +153,11 @@ func PushHandler(cmd *cobra.Command, args []string) error { ...@@ -149,6 +153,11 @@ func PushHandler(cmd *cobra.Command, args []string) error {
if err := client.Push(context.Background(), &request, fn); err != nil { if err := client.Push(context.Background(), &request, fn); err != nil {
return err return err
} }
if bar != nil && !bar.IsFinished() {
return errors.New("unexpected end to push model")
}
return nil return nil
} }
...@@ -235,12 +244,18 @@ func pull(model string, insecure bool) error { ...@@ -235,12 +244,18 @@ func pull(model string, insecure bool) error {
currentDigest = "" currentDigest = ""
fmt.Println(resp.Status) fmt.Println(resp.Status)
} }
return nil return nil
} }
if err := client.Pull(context.Background(), &request, fn); err != nil { if err := client.Pull(context.Background(), &request, fn); err != nil {
return err return err
} }
if bar != nil && !bar.IsFinished() {
return errors.New("unexpected end to pull model")
}
return nil return nil
} }
...@@ -304,6 +319,10 @@ func generate(cmd *cobra.Command, model, prompt string) error { ...@@ -304,6 +319,10 @@ func generate(cmd *cobra.Command, model, prompt string) error {
fmt.Println() fmt.Println()
fmt.Println() fmt.Println()
if !latest.Done {
return errors.New("unexpected end of response")
}
verbose, err := cmd.Flags().GetBool("verbose") verbose, err := cmd.Flags().GetBool("verbose")
if err != nil { if err != nil {
return err return err
...@@ -664,9 +683,10 @@ func NewCLI() *cobra.Command { ...@@ -664,9 +683,10 @@ func NewCLI() *cobra.Command {
log.SetFlags(log.LstdFlags | log.Lshortfile) log.SetFlags(log.LstdFlags | log.Lshortfile)
rootCmd := &cobra.Command{ rootCmd := &cobra.Command{
Use: "ollama", Use: "ollama",
Short: "Large language model runner", Short: "Large language model runner",
SilenceUsage: true, SilenceUsage: true,
SilenceErrors: true,
CompletionOptions: cobra.CompletionOptions{ CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true, DisableDefaultCmd: true,
}, },
......
...@@ -4,8 +4,9 @@ import ( ...@@ -4,8 +4,9 @@ import (
"context" "context"
"github.com/jmorganca/ollama/cmd" "github.com/jmorganca/ollama/cmd"
"github.com/spf13/cobra"
) )
func main() { func main() {
cmd.NewCLI().ExecuteContext(context.Background()) cobra.CheckErr(cmd.NewCLI().ExecuteContext(context.Background()))
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment