From ea3b735904218abc0444db52da696efc7ab6573b Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 4 Aug 2023 17:26:43 +0100 Subject: [PATCH 1/2] fix(cli): clistat: accept positional arg for stat disk cmd --- cli/stat.go | 8 ++++++++ cli/stat_test.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/cli/stat.go b/cli/stat.go index 3e32c4187f93b..3657a4f3c71c9 100644 --- a/cli/stat.go +++ b/cli/stat.go @@ -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 `. + 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 } diff --git a/cli/stat_test.go b/cli/stat_test.go index d92574e339b89..d7500359b89d8 100644 --- a/cli/stat_test.go +++ b/cli/stat_test.go @@ -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(), "no such file or directory") + }) } From 118a8a1bf8d9231e7b0ed48dbbc55ac33765b512 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 4 Aug 2023 17:37:46 +0100 Subject: [PATCH 2/2] fixup! fix(cli): clistat: accept positional arg for stat disk cmd --- cli/stat_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/stat_test.go b/cli/stat_test.go index d7500359b89d8..e90836e992094 100644 --- a/cli/stat_test.go +++ b/cli/stat_test.go @@ -180,6 +180,6 @@ func TestStatDiskCmd(t *testing.T) { inv.Stdout = buf err := inv.WithContext(ctx).Run() require.Error(t, err) - require.Contains(t, err.Error(), "no such file or directory") + require.Contains(t, err.Error(), `not found: "/this/path/does/not/exist"`) }) }