- Docker:新增只读、生命周期、清理、Compose 共 32 条命令,Linux 自动适配 podman - 危险命令 clearall/prunevolumes 未带 --yes 时仅提示并以退出码 2 结束 - 需要容器/镜像名的命令做必填参数校验,-- 之后参数计入位置参数 - diagnose:自动识别 Docker/Podman 容器或 K8s Pod,输出状态、根因、依据、建议并附日志与事件 - diagnose 中 -n 表示 namespace,其余命令 -n 仍为 --dry-run - 新增内置动作桥接与平台变体 helper,补充单元/集成/CLI 测试与 README
49 lines
1.3 KiB
Go
49 lines
1.3 KiB
Go
package executor
|
|
|
|
import (
|
|
"context"
|
|
"io"
|
|
|
|
"gitea.odboy.cn/odboy/kenaito-kopsc/internal/diagnose"
|
|
"gitea.odboy.cn/odboy/kenaito-kopsc/internal/platform"
|
|
)
|
|
|
|
// BuiltinRequest carries the caller's arguments and output streams to an
|
|
// in-process command implementation.
|
|
type BuiltinRequest struct {
|
|
Args []string
|
|
Stdout io.Writer
|
|
Stderr io.Writer
|
|
Info platform.Info
|
|
}
|
|
|
|
// Builtin executes a command inside kopsc instead of spawning a child. It is
|
|
// used where no portable system utility exists (for example du on Windows).
|
|
type Builtin func(ctx context.Context, req BuiltinRequest) error
|
|
|
|
var builtins = map[string]Builtin{
|
|
"disk.usage": runDiskUsage,
|
|
"diagnose": runDiagnose,
|
|
}
|
|
|
|
// runDiagnose bridges the registry builtin to the diagnose package.
|
|
func runDiagnose(ctx context.Context, req BuiltinRequest) error {
|
|
service := diagnose.New(req.Info, diagnose.ExecRunner{}, req.Stdout, req.Stderr)
|
|
return service.Run(ctx, req.Args)
|
|
}
|
|
|
|
// LookupBuiltin returns the implementation registered under name.
|
|
func LookupBuiltin(name string) (Builtin, bool) {
|
|
fn, ok := builtins[name]
|
|
return fn, ok
|
|
}
|
|
|
|
// BuiltinNames lists the registered builtin implementations.
|
|
func BuiltinNames() []string {
|
|
names := make([]string, 0, len(builtins))
|
|
for name := range builtins {
|
|
names = append(names, name)
|
|
}
|
|
return names
|
|
}
|