Skip to content
Merged
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: 7 additions & 6 deletions cmd/project/samples.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,17 @@ var samplesLanguageFlag string

func NewSamplesCommand(clients *shared.ClientFactory) *cobra.Command {
cmd := &cobra.Command{
Use: "samples",
Use: "samples [name]",
Aliases: []string{"sample"},
Short: "List available sample apps",
Long: "List and create an app from the available samples",
Example: style.ExampleCommandsf([]style.ExampleCommand{
{Command: "samples", Meaning: "Select a sample app to create"},
{
Meaning: "Select a sample app to create",
Command: "samples my-project",
},
}),
Args: cobra.MaximumNArgs(0),
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clients.Config.SetFlags(cmd)
return runSamplesCommand(clients, cmd, args)
Expand Down Expand Up @@ -77,9 +80,7 @@ func runSamplesCommand(clients *shared.ClientFactory, cmd *cobra.Command, args [

// If preferred directory name is passed in as an argument to the `create`
// command first, honor that preference and use it to create the project
if len(args) > 0 {
createCmd.SetArgs([]string{args[0]})
}
createCmd.SetArgs(args)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: Ah, much more elegant!


// Execute the `create` command with the set flag
return createCmd.ExecuteContext(ctx)
Expand Down
7 changes: 5 additions & 2 deletions cmd/project/samples_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
func TestSamplesCommand(t *testing.T) {
testutil.TableTestCommand(t, testutil.CommandTests{
"creates a template from a trusted sample": {
CmdArgs: []string{},
CmdArgs: []string{"my-sample-app"},
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
createPkg.GetSampleRepos = func(client createPkg.Sampler) ([]createPkg.GithubRepo, error) {
repos := []createPkg.GithubRepo{
Expand Down Expand Up @@ -72,9 +72,12 @@ func TestSamplesCommand(t *testing.T) {
nil,
)
CreateFunc = func(ctx context.Context, clients *shared.ClientFactory, log *logger.Logger, createArgs createPkg.CreateArgs) (appDirPath string, err error) {
return "", nil
return createArgs.AppName, nil
}
},
ExpectedOutputs: []string{
"cd my-sample-app/",
},
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
for _, call := range cm.IO.Calls {
switch call.Method {
Expand Down
Loading