Skip to content

Commit

Permalink
cmd/ask: display runbooks instead of commands
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi4 committed May 14, 2024
1 parent 58b77eb commit aea8a36
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type Client interface {
GenerateRunbook(ctx context.Context, commands []string) (*GeneratedRunbook, error)
RunbookByID(ctx context.Context, id string) (*Runbook, error)
Runbooks(ctx context.Context) ([]RunbookInfo, error)
Ask(ctx context.Context, question QuestionInfo) (*Answer, error)
Ask(ctx context.Context, question QuestionInfo) (*Runbook, error)
}

type RecordedCommand struct {
Expand Down Expand Up @@ -247,11 +247,11 @@ type CommandExplanation struct {
Explanation string `json:"explanation"`
}

func (c *client) Ask(ctx context.Context, question QuestionInfo) (*Answer, error) {
func (c *client) Ask(ctx context.Context, question QuestionInfo) (*Runbook, error) {
return ask(ctx, c.cl, c.apiURL("/api/v1/public/ask"), question)
}

func ask(ctx context.Context, cl *http.Client, apiURL string, question QuestionInfo) (*Answer, error) {
func ask(ctx context.Context, cl *http.Client, apiURL string, question QuestionInfo) (*Runbook, error) {
bs, err := json.Marshal(question)
if err != nil {
return nil, err
Expand All @@ -268,9 +268,9 @@ func ask(ctx context.Context, cl *http.Client, apiURL string, question QuestionI
}
defer resp.Body.Close()

var answer Answer
if err := json.NewDecoder(resp.Body).Decode(&answer); err != nil {
var runbook Runbook
if err := json.NewDecoder(resp.Body).Decode(&runbook); err != nil {
return nil, err
}
return &answer, nil
return &runbook, nil
}
2 changes: 1 addition & 1 deletion client/guest.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,6 @@ func (g *guest) Runbooks(ctx context.Context) ([]RunbookInfo, error) {
return nil, fmt.Errorf("%w: %v", ErrCannotUseGuest, "list runbooks")
}

func (g *guest) Ask(ctx context.Context, question QuestionInfo) (*Answer, error) {
func (g *guest) Ask(ctx context.Context, question QuestionInfo) (*Runbook, error) {
return ask(ctx, g.cl, g.apiURL("/api/v1/public/ask"), question)
}

0 comments on commit aea8a36

Please sign in to comment.