mirror of
https://github.com/coder/coder.git
synced 2026-09-22 05:05:20 +08:00
fix(cli): clistat: accept positional arg for stat disk cmd (#8911)
This commit is contained in:
@@ -233,8 +233,16 @@ func (*RootCmd) statDisk(s *clistat.Statter) *clibase.Cmd {
|
||||
},
|
||||
Handler: func(inv *clibase.Invocation) error {
|
||||
pfx := clistat.ParsePrefix(prefixArg)
|
||||
// Users may also call `coder stat disk <path>`.
|
||||
if len(inv.Args) > 0 {
|
||||
pathArg = inv.Args[0]
|
||||
}
|
||||
ds, err := s.Disk(pfx, pathArg)
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// fmt.Errorf produces a more concise error.
|
||||
return fmt.Errorf("not found: %q", pathArg)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -170,4 +170,16 @@ func TestStatDiskCmd(t *testing.T) {
|
||||
require.NotZero(t, *tmp.Total)
|
||||
require.Equal(t, "B", tmp.Unit)
|
||||
})
|
||||
|
||||
t.Run("PosArg", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
||||
t.Cleanup(cancel)
|
||||
inv, _ := clitest.New(t, "stat", "disk", "/this/path/does/not/exist", "--output=text")
|
||||
buf := new(bytes.Buffer)
|
||||
inv.Stdout = buf
|
||||
err := inv.WithContext(ctx).Run()
|
||||
require.Error(t, err)
|
||||
require.Contains(t, err.Error(), `not found: "/this/path/does/not/exist"`)
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user