Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion cli/exp_task_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ import (
"github.com/google/uuid"
"golang.org/x/xerrors"

"github.com/coder/serpent"

"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/serpent"
)

func (r *RootCmd) taskCreate() *serpent.Command {
Expand All @@ -28,6 +29,16 @@ func (r *RootCmd) taskCreate() *serpent.Command {
cmd := &serpent.Command{
Use: "create [input]",
Short: "Create an experimental task",
Long: FormatExamples(
Example{
Description: "Create a task with all flags specified",
Command: "coder exp task create \"Refactor CLI auth to use OAuth flow\" --template coder --org coder",
},
Example{
Description: "Create a task with a preset",
Command: "coder exp task create \"Add new API endpoint\" --template coder --preset backend",
},
),
Middleware: serpent.Chain(
serpent.RequireRangeArgs(0, 1),
r.InitClient(client),
Expand Down
26 changes: 25 additions & 1 deletion cli/exp_task_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,13 @@ import (
"github.com/google/uuid"
"github.com/stretchr/testify/assert"

"github.com/coder/serpent"

"github.com/coder/coder/v2/cli/clitest"
"github.com/coder/coder/v2/cli/cliui"
"github.com/coder/coder/v2/coderd/httpapi"
"github.com/coder/coder/v2/codersdk"
"github.com/coder/coder/v2/testutil"
"github.com/coder/serpent"
)

func TestTaskCreate(t *testing.T) {
Expand Down Expand Up @@ -334,3 +335,26 @@ func TestTaskCreate(t *testing.T) {
})
}
}

func TestTaskCreateHelp(t *testing.T) {
t.Parallel()

ctx := testutil.Context(t, testutil.WaitShort)

inv, _ := clitest.New(t, "exp", "task", "create", "--help")
var sb strings.Builder
inv.Stdout = &sb
inv.Stderr = &sb

err := inv.WithContext(ctx).Run()
assert.NoError(t, err)

output := sb.String()
// Verify that the examples are present in the help output
assert.Contains(t, output, "Create a task with all flags specified")
assert.Contains(t, output, "coder exp task create \"Refactor CLI auth to use OAuth flow\"")
assert.Contains(t, output, "--template coder --org coder")
assert.Contains(t, output, "Create a task with a preset")
assert.Contains(t, output, "coder exp task create \"Add new API endpoint\"")
assert.Contains(t, output, "--preset backend")
}