Skip to content

Commit

Permalink
set non-zero error code on error
Browse files Browse the repository at this point in the history
  • Loading branch information
mxyng committed Aug 14, 2023
1 parent 2ab2009 commit 76b85bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
26 changes: 23 additions & 3 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func CreateHandler(cmd *cobra.Command, args []string) error {
spinner = NewSpinner(resp.Status)
go spinner.Spin(100 * time.Millisecond)
}

return nil
}

Expand All @@ -84,6 +85,9 @@ func CreateHandler(cmd *cobra.Command, args []string) error {

if spinner != nil {
spinner.Stop()
if spinner.description != "success" {
return errors.New("unexpected end to create model")
}
}

return nil
Expand Down Expand Up @@ -149,6 +153,11 @@ func PushHandler(cmd *cobra.Command, args []string) error {
if err := client.Push(context.Background(), &request, fn); err != nil {
return err
}

if bar != nil && !bar.IsFinished() {
return errors.New("unexpected end to push model")
}

return nil
}

Expand Down Expand Up @@ -235,12 +244,18 @@ func pull(model string, insecure bool) error {
currentDigest = ""
fmt.Println(resp.Status)
}

return nil
}

if err := client.Pull(context.Background(), &request, fn); err != nil {
return err
}

if bar != nil && !bar.IsFinished() {
return errors.New("unexpected end to pull model")
}

return nil
}

Expand Down Expand Up @@ -304,6 +319,10 @@ func generate(cmd *cobra.Command, model, prompt string) error {
fmt.Println()
fmt.Println()

if !latest.Done {
return errors.New("unexpected end of response")
}

verbose, err := cmd.Flags().GetBool("verbose")
if err != nil {
return err
Expand Down Expand Up @@ -664,9 +683,10 @@ func NewCLI() *cobra.Command {
log.SetFlags(log.LstdFlags | log.Lshortfile)

rootCmd := &cobra.Command{
Use: "ollama",
Short: "Large language model runner",
SilenceUsage: true,
Use: "ollama",
Short: "Large language model runner",
SilenceUsage: true,
SilenceErrors: true,
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import (
"context"

"github.com/jmorganca/ollama/cmd"
"github.com/spf13/cobra"
)

func main() {
cmd.NewCLI().ExecuteContext(context.Background())
cobra.CheckErr(cmd.NewCLI().ExecuteContext(context.Background()))
}

0 comments on commit 76b85bc

Please sign in to comment.