feat: 新增 disk usage 内置命令(跨平台 du 等价)
- 注册表新增 Variant.Builtin 内置动作,与 Argv 互斥并参与平台匹配 - disk.usage 支持位置参数与 --path/--path=,输出按大小降序并带合计 - Unix 用设备号实现 -x 不跨文件系统,Windows 降级为不跟随 reparse point - list/help/explain 支持展示内置动作,补充单元与 CLI 测试、README
This commit is contained in:
@@ -22,7 +22,11 @@ type Variant struct {
|
||||
Match Match
|
||||
Argv []string // program followed by arguments
|
||||
Shell bool // run through the platform shell instead of exec'ing Argv[0]
|
||||
Note string // human-readable rationale shown by `kopsc explain`
|
||||
// Builtin names an in-process implementation registered with the executor.
|
||||
// It is mutually exclusive with Argv and lets kopsc provide commands that
|
||||
// have no equivalent system utility (for example on Windows).
|
||||
Builtin string
|
||||
Note string // human-readable rationale shown by `kopsc explain`
|
||||
}
|
||||
|
||||
// Command is a platform-neutral intent, e.g. "docker.clearsafe".
|
||||
@@ -73,7 +77,13 @@ func (r *Registry) Validate() error {
|
||||
}
|
||||
|
||||
for j, variant := range cmd.Variants {
|
||||
if len(variant.Argv) == 0 || strings.TrimSpace(variant.Argv[0]) == "" {
|
||||
if len(variant.Argv) == 0 && variant.Builtin == "" {
|
||||
return fmt.Errorf("command %q variant #%d: empty argv and no builtin", cmd.ID, j)
|
||||
}
|
||||
if len(variant.Argv) > 0 && variant.Builtin != "" {
|
||||
return fmt.Errorf("command %q variant #%d: argv and builtin are mutually exclusive", cmd.ID, j)
|
||||
}
|
||||
if len(variant.Argv) > 0 && strings.TrimSpace(variant.Argv[0]) == "" {
|
||||
return fmt.Errorf("command %q variant #%d: empty argv", cmd.ID, j)
|
||||
}
|
||||
if err := variant.Match.validate(); err != nil {
|
||||
|
||||
Reference in New Issue
Block a user