a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package agents
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"strings"
|
|
)
|
|
|
|
// PrintConfig writes a dry-run view of the configuration a single named adapter
|
|
// would install — the files it plans to touch, their action, and the keys it
|
|
// sets — as indented JSON, without writing anything to disk. It is the
|
|
// machine-readable companion to `init doctor`, scoped to one agent. Returns an
|
|
// error naming the registered agents when `name` matches none.
|
|
func PrintConfig(w io.Writer, reg *Registry, name string, env Env) error {
|
|
var found Adapter
|
|
var available []string
|
|
for _, a := range reg.All() {
|
|
available = append(available, a.Name())
|
|
if a.Name() == name {
|
|
found = a
|
|
}
|
|
}
|
|
if found == nil {
|
|
return fmt.Errorf("unknown agent %q; available: %s", name, strings.Join(available, ", "))
|
|
}
|
|
|
|
plan, err := found.Plan(env)
|
|
if err != nil {
|
|
return fmt.Errorf("plan %s: %w", found.Name(), err)
|
|
}
|
|
files := []FileAction{}
|
|
if plan != nil && plan.Files != nil {
|
|
files = plan.Files
|
|
}
|
|
|
|
enc := json.NewEncoder(w)
|
|
enc.SetIndent("", " ")
|
|
return enc.Encode(map[string]any{
|
|
"agent": found.Name(),
|
|
"docs_url": found.DocsURL(),
|
|
"files": files,
|
|
})
|
|
}
|