Skip to content

Commit eb35802

Browse files
Merge pull request #219 from thedadams/confirm-context
enhance: add context to confirm call to get run context information
2 parents 44c8e8f + b9e7736 commit eb35802

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

pkg/confirm/confirm.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
type Confirm interface {
12-
Confirm(prompt string) error
12+
Confirm(ctx context.Context, prompt string) error
1313
}
1414

1515
type confirmer struct{}
@@ -23,13 +23,13 @@ func Promptf(ctx context.Context, fmtString string, args ...any) error {
2323
if !ok {
2424
return nil
2525
}
26-
return c.Confirm(fmt.Sprintf(fmtString, args...))
26+
return c.Confirm(ctx, fmt.Sprintf(fmtString, args...))
2727
}
2828

2929
type TextPrompt struct {
3030
}
3131

32-
func (t TextPrompt) Confirm(prompt string) error {
32+
func (t TextPrompt) Confirm(_ context.Context, prompt string) error {
3333
var result bool
3434
err := survey.AskOne(&survey.Confirm{
3535
Message: prompt,

pkg/engine/engine.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ func (c *Context) SubCall(ctx context.Context, toolID, callID string) (Context,
109109
}, nil
110110
}
111111

112+
type engineContext struct{}
113+
114+
func FromContext(ctx context.Context) (*Context, bool) {
115+
c, ok := ctx.Value(engineContext{}).(*Context)
116+
return c, ok
117+
}
118+
119+
func (c *Context) WrappedContext() context.Context {
120+
return context.WithValue(c.Ctx, engineContext{}, c)
121+
}
122+
112123
func (e *Engine) Start(ctx Context, input string) (*Return, error) {
113124
tool := ctx.Tool
114125

@@ -120,7 +131,7 @@ func (e *Engine) Start(ctx Context, input string) (*Return, error) {
120131
} else if tool.IsOpenAPI() {
121132
return e.runOpenAPI(tool, input)
122133
}
123-
s, err := e.runCommand(ctx.Ctx, tool, input)
134+
s, err := e.runCommand(ctx.WrappedContext(), tool, input)
124135
if err != nil {
125136
return nil, err
126137
}

pkg/runner/runner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ func (r *Runner) call(callCtx engine.Context, monitor Monitor, env []string, inp
182182
}
183183
}
184184

185-
func streamProgress(callCtx *engine.Context, monitor Monitor) (chan types.CompletionStatus, func()) {
185+
func streamProgress(callCtx *engine.Context, monitor Monitor) (chan<- types.CompletionStatus, func()) {
186186
progress := make(chan types.CompletionStatus)
187187

188188
wg := sync.WaitGroup{}

0 commit comments

Comments
 (0)