From 26bc68a50783b1daefb17dd0b8fd92208213e334 Mon Sep 17 00:00:00 2001 From: "@zimeg" Date: Tue, 24 Jun 2025 21:04:37 -0700 Subject: [PATCH 1/2] fix: accept the app name as an argument to the 'samples' command --- cmd/project/samples.go | 9 ++++++--- cmd/project/samples_test.go | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/cmd/project/samples.go b/cmd/project/samples.go index d84325a6..f4e7684d 100644 --- a/cmd/project/samples.go +++ b/cmd/project/samples.go @@ -29,14 +29,17 @@ var samplesGitBranchFlag 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) diff --git a/cmd/project/samples_test.go b/cmd/project/samples_test.go index 0bc7e96d..e90918d5 100644 --- a/cmd/project/samples_test.go +++ b/cmd/project/samples_test.go @@ -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{ @@ -64,9 +64,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 { From 66314ac892126591c5c0bf96bbc0cee38a9ab16b Mon Sep 17 00:00:00 2001 From: "@zimeg" Date: Tue, 24 Jun 2025 21:09:20 -0700 Subject: [PATCH 2/2] fix: provide all arguments of the samples command to create --- cmd/project/samples.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/cmd/project/samples.go b/cmd/project/samples.go index f4e7684d..8a0622a3 100644 --- a/cmd/project/samples.go +++ b/cmd/project/samples.go @@ -78,9 +78,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) // Execute the `create` command with the set flag return createCmd.ExecuteContext(ctx)