Skip to content

Commit 2538417

Browse files
committed
feat: add no-copy flag to project validate command to skip temporary directory creation
1 parent b6d7128 commit 2538417

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

cmd/project/project_validate.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/shopware/shopware-cli/internal/system"
1212
"github.com/shopware/shopware-cli/internal/verifier"
13+
"github.com/shopware/shopware-cli/logging"
1314
)
1415

1516
var projectValidateCmd = &cobra.Command{
@@ -22,6 +23,7 @@ var projectValidateCmd = &cobra.Command{
2223
reportingFormat, _ := cmd.Flags().GetString("reporter")
2324
only, _ := cmd.Flags().GetString("only")
2425
tmpDir, err := os.MkdirTemp(os.TempDir(), "analyse-project-*")
26+
noCopy, _ := cmd.Flags().GetBool("no-copy")
2527
if err != nil {
2628
return fmt.Errorf("cannot create temporary directory: %w", err)
2729
}
@@ -46,8 +48,18 @@ var projectValidateCmd = &cobra.Command{
4648
reportingFormat = verifier.DetectDefaultReporter()
4749
}
4850

49-
if err := system.CopyFiles(projectPath, tmpDir); err != nil {
50-
return err
51+
if !noCopy {
52+
if err := system.CopyFiles(projectPath, tmpDir); err != nil {
53+
return err
54+
}
55+
56+
defer func() {
57+
if err := os.RemoveAll(tmpDir); err != nil {
58+
logging.FromContext(cmd.Context()).Error("Failed to remove temporary directory:", err)
59+
}
60+
}()
61+
} else {
62+
tmpDir = projectPath
5163
}
5264

5365
toolCfg, err := verifier.GetConfigFromProject(tmpDir)
@@ -85,4 +97,5 @@ func init() {
8597
projectRootCmd.AddCommand(projectValidateCmd)
8698
projectValidateCmd.PersistentFlags().String("reporter", "", "Reporting format (summary, json, github, junit, markdown)")
8799
projectValidateCmd.PersistentFlags().String("only", "", "Run only specific tools by name (comma-separated, e.g. phpstan,eslint)")
100+
projectValidateCmd.PersistentFlags().Bool("no-copy", false, "Do not copy project files to temporary directory")
88101
}

0 commit comments

Comments
 (0)