Skip to content

Commit e4bd87b

Browse files
committed
more progress
1 parent 01ac928 commit e4bd87b

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

cli/cliarg/cliarg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
//
99
// Error: this command accepts 'workspace' as an argument, received no arguments. Pass in 'workspace' or call command with '--help' to see an example.")
1010
//
11-
package cliflag
11+
package cliarg
1212

1313
import (
1414
"fmt"
@@ -21,7 +21,7 @@ func ExactNamedArg(namedArg string, customErrorMessage string) cobra.PositionalA
2121
return func(cmd *cobra.Command, args []string) error {
2222
expectedNumOfArgs := 1
2323
if len(args) != expectedNumOfArgs {
24-
return fmt.Errorf("this command accepts <%s> as an argument, received no arguments. Pass in arg or call command with '--help' to see an example.", namedArg)
24+
return fmt.Errorf("this command accepts <%s> as an argument, received no arguments. <%s>", namedArg, customErrorMessage)
2525
}
2626
return nil
2727
}

cli/cliarg/cliflag_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package cliarg_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/coder/coder/cli/cliarg"
7+
"github.com/coder/coder/cli/clitest"
8+
"github.com/stretchr/testify/require"
9+
)
10+
11+
func TestCliarg(t *testing.T) {
12+
t.Run("No errors", func(t *testing.T) {
13+
namedArg := "workspace"
14+
customErrorMessage := "Please call with a workspace arg"
15+
fun := cliarg.ExactNamedArg(namedArg, customErrorMessage)
16+
args := []string{"myWorkspace"}
17+
cmd, _ := clitest.New(t, "delete", "myWorkspace")
18+
var want *string = nil
19+
got := fun(cmd, args)
20+
require.Nil(t, want, got)
21+
})
22+
t.Run("Custom error message", func(t *testing.T) {
23+
namedArg := "workspace"
24+
customErrorMessage := "Please call with a workspace arg"
25+
fun := cliarg.ExactNamedArg(namedArg, customErrorMessage)
26+
var args []string
27+
cmd, _ := clitest.New(t, "delete")
28+
got := fun(cmd, args)
29+
require.ErrorContains(t, got, customErrorMessage)
30+
})
31+
}

0 commit comments

Comments
 (0)