Skip to content

Commit b6953db

Browse files
authored
feat: accept the app name as an argument to the 'samples' command (#140)
1 parent f59f7b7 commit b6953db

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

cmd/project/samples.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,17 @@ var samplesLanguageFlag string
3030

3131
func NewSamplesCommand(clients *shared.ClientFactory) *cobra.Command {
3232
cmd := &cobra.Command{
33-
Use: "samples",
33+
Use: "samples [name]",
3434
Aliases: []string{"sample"},
3535
Short: "List available sample apps",
3636
Long: "List and create an app from the available samples",
3737
Example: style.ExampleCommandsf([]style.ExampleCommand{
38-
{Command: "samples", Meaning: "Select a sample app to create"},
38+
{
39+
Meaning: "Select a sample app to create",
40+
Command: "samples my-project",
41+
},
3942
}),
40-
Args: cobra.MaximumNArgs(0),
43+
Args: cobra.MaximumNArgs(1),
4144
RunE: func(cmd *cobra.Command, args []string) error {
4245
clients.Config.SetFlags(cmd)
4346
return runSamplesCommand(clients, cmd, args)
@@ -77,9 +80,7 @@ func runSamplesCommand(clients *shared.ClientFactory, cmd *cobra.Command, args [
7780

7881
// If preferred directory name is passed in as an argument to the `create`
7982
// command first, honor that preference and use it to create the project
80-
if len(args) > 0 {
81-
createCmd.SetArgs([]string{args[0]})
82-
}
83+
createCmd.SetArgs(args)
8384

8485
// Execute the `create` command with the set flag
8586
return createCmd.ExecuteContext(ctx)

cmd/project/samples_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import (
3232
func TestSamplesCommand(t *testing.T) {
3333
testutil.TableTestCommand(t, testutil.CommandTests{
3434
"creates a template from a trusted sample": {
35-
CmdArgs: []string{},
35+
CmdArgs: []string{"my-sample-app"},
3636
Setup: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock, cf *shared.ClientFactory) {
3737
createPkg.GetSampleRepos = func(client createPkg.Sampler) ([]createPkg.GithubRepo, error) {
3838
repos := []createPkg.GithubRepo{
@@ -72,9 +72,12 @@ func TestSamplesCommand(t *testing.T) {
7272
nil,
7373
)
7474
CreateFunc = func(ctx context.Context, clients *shared.ClientFactory, log *logger.Logger, createArgs createPkg.CreateArgs) (appDirPath string, err error) {
75-
return "", nil
75+
return createArgs.AppName, nil
7676
}
7777
},
78+
ExpectedOutputs: []string{
79+
"cd my-sample-app/",
80+
},
7881
ExpectedAsserts: func(t *testing.T, ctx context.Context, cm *shared.ClientsMock) {
7982
for _, call := range cm.IO.Calls {
8083
switch call.Method {

0 commit comments

Comments
 (0)