Skip to content

Commit 82e0e2e

Browse files
authored
fix(cli): clistat: accept positional arg for stat disk cmd (#8911)
1 parent 6ded748 commit 82e0e2e

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

cli/stat.go

+8
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,16 @@ func (*RootCmd) statDisk(s *clistat.Statter) *clibase.Cmd {
233233
},
234234
Handler: func(inv *clibase.Invocation) error {
235235
pfx := clistat.ParsePrefix(prefixArg)
236+
// Users may also call `coder stat disk <path>`.
237+
if len(inv.Args) > 0 {
238+
pathArg = inv.Args[0]
239+
}
236240
ds, err := s.Disk(pfx, pathArg)
237241
if err != nil {
242+
if os.IsNotExist(err) {
243+
// fmt.Errorf produces a more concise error.
244+
return fmt.Errorf("not found: %q", pathArg)
245+
}
238246
return err
239247
}
240248

cli/stat_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,16 @@ func TestStatDiskCmd(t *testing.T) {
170170
require.NotZero(t, *tmp.Total)
171171
require.Equal(t, "B", tmp.Unit)
172172
})
173+
174+
t.Run("PosArg", func(t *testing.T) {
175+
t.Parallel()
176+
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
177+
t.Cleanup(cancel)
178+
inv, _ := clitest.New(t, "stat", "disk", "/this/path/does/not/exist", "--output=text")
179+
buf := new(bytes.Buffer)
180+
inv.Stdout = buf
181+
err := inv.WithContext(ctx).Run()
182+
require.Error(t, err)
183+
require.Contains(t, err.Error(), `not found: "/this/path/does/not/exist"`)
184+
})
173185
}

0 commit comments

Comments
 (0)