feat: 优化非 Docker 命令的易用性,修复带 digest 镜像无法按名称查找
- docker save/rmi:镜像名不再拼接 digest({{.Digest}} 对多数镜像输出
sha256:…,导致 alpine:3.20 被存成 alpine:3.20@sha256:… 而查不到),
digest 单独保存;同时修正自定义 --format 输出中 IMAGE ID 表头未被过滤
- diagnose:目标不存在时给出相似名称候选,无相似时列出当前存在的对象
- net.pids:无进程占用时向 stderr 提示且 stdout 保持为空,新增 --pid-file
- net.ports:默认输出跨平台一致的端口表格,--raw 保留原生命令输出
- disk.usage:路径可省略(默认当前目录),新增 --depth N 控制层级
This commit is contained in:
+25
-10
@@ -73,14 +73,17 @@ func TestLeafHelp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLeafPassesThroughArgs(t *testing.T) {
|
||||
// net.ports is a builtin now, so use a docker command whose argv is fixed
|
||||
// and whose passthrough the dry-run output shows.
|
||||
app, stdout, _ := testApp(centos("docker"))
|
||||
|
||||
code := app.Execute([]string{"net", "ports", "--dry-run", "--", "-l"})
|
||||
code := app.Execute([]string{"docker", "ps", "--dry-run", "--", "--filter", "status=running"})
|
||||
if code != 0 {
|
||||
t.Fatalf("exit code = %d", code)
|
||||
}
|
||||
if !strings.Contains(stdout.String(), "ss -tulnp -l") {
|
||||
t.Errorf("passthrough args missing:\n%s", stdout.String())
|
||||
out := stdout.String()
|
||||
if !strings.Contains(out, "docker ps") || !strings.Contains(out, "--filter status=running") {
|
||||
t.Errorf("passthrough args missing:\n%s", out)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -384,14 +387,26 @@ func TestDiskUsageAcceptsPathFlagThroughCLI(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiskUsageRequiresPathThroughCLI(t *testing.T) {
|
||||
app, _, stderr := testApp(centos("docker"))
|
||||
|
||||
if code := app.Execute([]string{"disk", "usage"}); code != 1 {
|
||||
t.Fatalf("exit code = %d, want 1", code)
|
||||
func TestDiskUsageDefaultsToCurrentDirectoryThroughCLI(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
if err := os.WriteFile(filepath.Join(dir, "payload.bin"), bytes.Repeat([]byte("x"), 2048), 0o644); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(stderr.String(), "必须提供路径") {
|
||||
t.Errorf("stderr = %s", stderr.String())
|
||||
old, err := os.Getwd()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := os.Chdir(dir); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer func() { _ = os.Chdir(old) }()
|
||||
|
||||
app, stdout, stderr := testApp(centos("docker"))
|
||||
if code := app.Execute([]string{"disk", "usage"}); code != 0 {
|
||||
t.Fatalf("exit code = %d, stderr=%s", code, stderr.String())
|
||||
}
|
||||
if !strings.Contains(stdout.String(), "payload.bin") {
|
||||
t.Errorf("omitting the path should analyse the current directory:\n%s", stdout.String())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user