Skip to content

Commit 937b7ab

Browse files
authored
Merge pull request #30 from shopwareLabs/feat/add-only-flag-to-commands
feat: add --only flag to run specific tools
2 parents 784c826 + 2245506 commit 937b7ab

15 files changed

+136
-5
lines changed

README.md

+31-2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,37 @@ The check command has multiple reporting options, you can use `--reporter` to sp
8383
- `github` - GitHub Actions output
8484
- `markdown` - markdown output
8585

86+
## Running Specific Tools
87+
88+
Instead of running all tools, you can choose to run specific tools using the `--only` flag. The following tools are available:
89+
90+
- `phpstan` - PHP static analysis
91+
- `sw-cli` - Shopware CLI validation checks
92+
- `stylelint` - CSS/SCSS linting
93+
- `twig` - Twig template checks
94+
- `admin-twig` - Admin Twig template checks
95+
- `php-cs-fixer` - PHP code style fixing
96+
- `prettier` - Code formatting
97+
- `eslint` - JavaScript/TypeScript linting
98+
- `rector` - PHP code refactoring
99+
100+
You can run a single tool:
101+
102+
```shell
103+
docker run --rm -v $(pwd):/ext ghcr.io/shopwarelabs/extension-verifier:latest check /ext --only phpstan
104+
```
105+
106+
Or run multiple tools by separating them with commas:
107+
108+
```shell
109+
docker run --rm -v $(pwd):/ext ghcr.io/shopwarelabs/extension-verifier:latest check /ext --only "phpstan,eslint,stylelint"
110+
```
111+
112+
This is particularly useful when:
113+
- You want to focus on specific aspects of your code
114+
- You want to run only the relevant tools for the files you've changed
115+
- You want to fix issues one tool at a time
116+
86117
## Refactoring
87118

88119
To run the refactoring, you can use following command:
@@ -142,8 +173,6 @@ The fixers are enabled by the supported Shopware Version by the constraint in th
142173

143174
Your plugin typically requires only `shopware/core`, but when you use classes from Storefront or Elasticsearch Bundle and they are required, you have to add `shopware/storefront` or `shopware/elasticsearch` also to the `require` in the composer.json. If those features are optional with `class_exists` checks, you want to add them into `require-dev`, so the dependencies are installed only for development, and PHPStan can recognize the files.
144175

145-
146-
147176
# Contribution
148177

149178
To run this tool locally you need PHP, Node, NPM and Go.

cmd_check.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,15 @@ var checkCommand = &cobra.Command{
8686

8787
var gr errgroup.Group
8888

89-
for _, tool := range tool.GetTools() {
89+
tools := tool.GetTools()
90+
only, _ := cmd.Flags().GetString("only")
91+
92+
tools, err = filterTools(tools, only)
93+
if err != nil {
94+
return err
95+
}
96+
97+
for _, tool := range tools {
9098
tool := tool
9199
gr.Go(func() error {
92100
return tool.Check(cmd.Context(), result, *toolCfg)
@@ -105,6 +113,7 @@ func init() {
105113
rootCmd.AddCommand(checkCommand)
106114
checkCommand.PersistentFlags().String("reporter", "", "Reporting format (summary, json, github, junit, markdown)")
107115
checkCommand.PersistentFlags().String("check-against", "highest", "Check against Shopware Version (highest, lowest)")
116+
checkCommand.PersistentFlags().String("only", "", "Run only specific tools by name (comma-separated, e.g. phpstan,eslint)")
108117
checkCommand.PreRunE = func(cmd *cobra.Command, args []string) error {
109118
reporter, _ := cmd.Flags().GetString("reporter")
110119
if reporter != "summary" && reporter != "json" && reporter != "github" && reporter != "junit" && reporter != "markdown" && reporter != "" {

cmd_fix.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,16 @@ var (
3939

4040
var gr errgroup.Group
4141

42-
for _, tool := range tool.GetTools() {
42+
tools := tool.GetTools()
43+
only, _ := cmd.Flags().GetString("only")
44+
45+
tools, err = filterTools(tools, only)
46+
if err != nil {
47+
return err
48+
}
49+
50+
for _, tool := range tools {
51+
tool := tool
4352
gr.Go(func() error {
4453
return tool.Fix(cmd.Context(), *toolCfg)
4554
})
@@ -56,5 +65,6 @@ var (
5665

5766
func init() {
5867
fixCommand.Flags().BoolVar(&allowNonGit, "allow-non-git", false, "Allow running the fix command on non-git repositories")
68+
fixCommand.Flags().String("only", "", "Run only specific tools by name (comma-separated, e.g. phpstan,eslint)")
5969
rootCmd.AddCommand(fixCommand)
6070
}

cmd_format.go

+11-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,16 @@ var formatCommand = &cobra.Command{
2828

2929
var gr errgroup.Group
3030

31-
for _, tool := range tool.GetTools() {
31+
tools := tool.GetTools()
32+
only, _ := cmd.Flags().GetString("only")
33+
34+
tools, err = filterTools(tools, only)
35+
if err != nil {
36+
return err
37+
}
38+
39+
for _, tool := range tools {
40+
tool := tool
3241
gr.Go(func() error {
3342
return tool.Format(cmd.Context(), *toolCfg, dryRun)
3443
})
@@ -45,4 +54,5 @@ var formatCommand = &cobra.Command{
4554
func init() {
4655
rootCmd.AddCommand(formatCommand)
4756
formatCommand.PersistentFlags().Bool("dry-run", false, "Dry run the formatting")
57+
formatCommand.PersistentFlags().String("only", "", "Run only specific tools by name (comma-separated, e.g. phpstan,eslint)")
4858
}

cmd_shared.go

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"strings"
6+
7+
"github.com/shopware/extension-verifier/internal/tool"
8+
)
9+
10+
func filterTools(tools []tool.Tool, only string) ([]tool.Tool, error) {
11+
if only == "" {
12+
return tools, nil
13+
}
14+
15+
var filteredTools []tool.Tool
16+
requestedTools := strings.Split(only, ",")
17+
18+
for _, requestedTool := range requestedTools {
19+
requestedTool = strings.TrimSpace(requestedTool)
20+
found := false
21+
22+
for _, t := range tools {
23+
if t.Name() == requestedTool {
24+
filteredTools = append(filteredTools, t)
25+
found = true
26+
break
27+
}
28+
}
29+
30+
if !found {
31+
return nil, fmt.Errorf("tool with name %q not found", requestedTool)
32+
}
33+
}
34+
35+
return filteredTools, nil
36+
}

internal/tool/admin_twig.go

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ import (
1717

1818
type AdminTwigLinter struct{}
1919

20+
func (a AdminTwigLinter) Name() string {
21+
return "admin-twig"
22+
}
23+
2024
func (a AdminTwigLinter) Check(ctx context.Context, check *Check, config ToolConfig) error {
2125
fixers := admintwiglinter.GetFixers(version.Must(version.NewVersion(config.MinShopwareVersion)))
2226

internal/tool/eslint.go

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ type EslintOutput []struct {
4141

4242
type Eslint struct{}
4343

44+
func (e Eslint) Name() string {
45+
return "eslint"
46+
}
47+
4448
func (e Eslint) Check(ctx context.Context, check *Check, config ToolConfig) error {
4549
cwd, err := os.Getwd()
4650

internal/tool/phpcsfixer.go

+4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ import (
1111

1212
type PHPCSFixer struct{}
1313

14+
func (p PHPCSFixer) Name() string {
15+
return "php-cs-fixer"
16+
}
17+
1418
func (p PHPCSFixer) Check(ctx context.Context, check *Check, config ToolConfig) error {
1519
return nil
1620
}

internal/tool/phpstan.go

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ type PhpStanOutput struct {
3939

4040
type PhpStan struct{}
4141

42+
func (p PhpStan) Name() string {
43+
return "phpstan"
44+
}
45+
4246
func (p PhpStan) configExists(pluginPath string) bool {
4347
for _, config := range possiblePHPStanConfigs {
4448
if _, err := os.Stat(path.Join(pluginPath, config)); err == nil {

internal/tool/prettier.go

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ Resources/store/**
1818

1919
type Prettier struct{}
2020

21+
func (b Prettier) Name() string {
22+
return "prettier"
23+
}
24+
2125
func (b Prettier) Check(ctx context.Context, check *Check, config ToolConfig) error {
2226
return nil
2327
}

internal/tool/rector.go

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import (
1010

1111
type Rector struct{}
1212

13+
func (r Rector) Name() string {
14+
return "rector"
15+
}
16+
1317
func (r Rector) Check(ctx context.Context, check *Check, config ToolConfig) error {
1418
return nil
1519
}

internal/tool/stylelint.go

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ type StylelintOutput []struct {
3232

3333
type StyleLint struct{}
3434

35+
func (s StyleLint) Name() string {
36+
return "stylelint"
37+
}
38+
3539
func (s StyleLint) Check(ctx context.Context, check *Check, config ToolConfig) error {
3640
cwd, err := os.Getwd()
3741
if err != nil {

internal/tool/sw_cli.go

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import (
88

99
type SWCLI struct{}
1010

11+
func (s SWCLI) Name() string {
12+
return "sw-cli"
13+
}
14+
1115
func (s SWCLI) Check(ctx context.Context, check *Check, config ToolConfig) error {
1216
if config.Extension == nil {
1317
return nil

internal/tool/tool.go

+1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ type ToolConfigIgnore struct {
4444
}
4545

4646
type Tool interface {
47+
Name() string
4748
Check(ctx context.Context, check *Check, config ToolConfig) error
4849
Fix(ctx context.Context, config ToolConfig) error
4950
Format(ctx context.Context, config ToolConfig, dryRun bool) error

internal/tool/twig.go

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ import (
1818

1919
type Twig struct{}
2020

21+
func (t Twig) Name() string {
22+
return "twig"
23+
}
24+
2125
func (t Twig) Check(ctx context.Context, check *Check, config ToolConfig) error {
2226
return nil
2327
}

0 commit comments

Comments
 (0)