Skip to content

Commit 8615b67

Browse files
committed
STAC-22599: Adding stackpack scaffold command
1 parent 60b00aa commit 8615b67

3 files changed

Lines changed: 11 additions & 5 deletions

File tree

cmd/stackpack/stackpack_scaffold.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package stackpack
22

33
import (
44
"fmt"
5+
"os"
56
"strings"
67

78
"github.com/spf13/cobra"
@@ -65,7 +66,7 @@ sts stackpack scaffold --template-github-repo stackvista/my-templates --name my-
6566
cmd.Flags().StringVar(&args.TemplateGitHubPath, "template-github-path", "", fmt.Sprintf("Path within the repository containing template subdirectories (default: %s)", defaultTemplateGitHubPath))
6667

6768
// Common flags
68-
cmd.Flags().StringVar(&args.DestinationDir, "destination-dir", ".", "Target directory where scaffolded files will be created")
69+
cmd.Flags().StringVar(&args.DestinationDir, "destination-dir", "", "Target directory where scaffolded files will be created. If not specified, uses current working directory")
6970
cmd.Flags().StringVar(&args.Name, "name", "", "Name of the stackpack (required)")
7071
cmd.Flags().StringVar(&args.TemplateName, "template-name", defaultTemplateName, fmt.Sprintf("Name of the template subdirectory to use (default: %s)", defaultTemplateName))
7172
cmd.Flags().BoolVar(&args.Force, "force", false, "Overwrite existing files without prompting")
@@ -83,6 +84,14 @@ func RunStackpackScaffoldCommand(args *ScaffoldArgs) func(cli *di.Deps, cmd *cob
8384
return func(cli *di.Deps, cmd *cobra.Command) common.CLIError {
8485
// Create template source based on which source was specified
8586
var source scaffold.TemplateSource
87+
var err error
88+
89+
if args.DestinationDir == "" {
90+
args.DestinationDir, err = os.Getwd()
91+
if err != nil {
92+
return common.NewRuntimeError(fmt.Errorf("failed to get current working directory: %w", err))
93+
}
94+
}
8695

8796
if args.TemplateLocalDir != "" {
8897
source = scaffold.NewLocalDirSource(args.TemplateLocalDir, args.TemplateName)

cmd/stackpack/stackpack_scaffold_test.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,6 @@ func TestStackpackScaffoldCommand_DefaultValues(t *testing.T) {
520520
templateNameFlag := flags.Lookup("template-name")
521521
assert.Equal(t, defaultTemplateName, templateNameFlag.DefValue)
522522

523-
destinationDirFlag := flags.Lookup("destination-dir")
524-
assert.Equal(t, ".", destinationDirFlag.DefValue)
525-
526523
forceFlag := flags.Lookup("force")
527524
assert.Equal(t, "false", forceFlag.DefValue)
528525
}

pkg/scaffold/scaffolder.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func (s *Scaffolder) copyToDestinationWithResult(renderedDir string) (*CopyResul
398398
if !s.jsonOutput && s.printer != nil {
399399
s.printer.PrintWarn("The following files already exist and would be overwritten:")
400400
for _, file := range conflicts {
401-
s.printer.PrintLn(" " + file)
401+
s.printer.PrintLn(" " + filepath.Join(s.destination, file))
402402
}
403403
s.printer.PrintLn("")
404404
s.printer.PrintLn("Use --force flag to overwrite existing files, or remove/rename the conflicting files.")

0 commit comments

Comments
 (0)