Add Promptkit configuration and inspection seams
This commit is contained in:
59
internal/cli/executor_factory.go
Normal file
59
internal/cli/executor_factory.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
promptkitadapter "gitea.maximumdirect.net/eric/weatherreporter/internal/adapters/promptkit"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/config"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/promptexec"
|
||||
)
|
||||
|
||||
// PromptExecutorConfig is the project-owned construction input for one prompt
|
||||
// executor. It keeps adapter implementation types out of Runner's API.
|
||||
type PromptExecutorConfig struct {
|
||||
Profile string
|
||||
ProfileFile string
|
||||
ProfileDirectory string
|
||||
Timeout time.Duration
|
||||
LocalEndpoint string
|
||||
LocalConcurrencyLimit int
|
||||
}
|
||||
|
||||
// ExecutorFactory constructs one executor for an action.
|
||||
type ExecutorFactory func(PromptExecutorConfig) (promptexec.Executor, error)
|
||||
|
||||
func (r Runner) promptExecutor(cfg config.PromptkitConfig) (promptexec.Executor, error) {
|
||||
factory := r.ExecutorFactory
|
||||
if factory == nil {
|
||||
factory = newPromptkitExecutor
|
||||
}
|
||||
return factory(promptExecutorConfig(cfg))
|
||||
}
|
||||
|
||||
func promptExecutorConfig(cfg config.PromptkitConfig) PromptExecutorConfig {
|
||||
result := PromptExecutorConfig{
|
||||
Profile: cfg.Profile,
|
||||
ProfileFile: cfg.ProfileFile,
|
||||
ProfileDirectory: cfg.ProfileDir,
|
||||
Timeout: cfg.Timeout,
|
||||
}
|
||||
if cfg.Local.Endpoint != "" {
|
||||
result.LocalEndpoint = cfg.Local.Endpoint
|
||||
result.LocalConcurrencyLimit = cfg.Local.ConcurrencyLimit
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func newPromptkitExecutor(cfg PromptExecutorConfig) (promptexec.Executor, error) {
|
||||
return promptkitadapter.New(promptkitAdapterConfig(cfg))
|
||||
}
|
||||
|
||||
func promptkitAdapterConfig(cfg PromptExecutorConfig) promptkitadapter.Config {
|
||||
return promptkitadapter.Config{
|
||||
ProfileDirectory: cfg.ProfileDirectory,
|
||||
ProfileFile: cfg.ProfileFile,
|
||||
LocalEndpoint: cfg.LocalEndpoint,
|
||||
LocalConcurrencyLimit: cfg.LocalConcurrencyLimit,
|
||||
Timeout: cfg.Timeout,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user