Skip to content

Commit 20f1fe8

Browse files
authored
Merge pull request #1391 from shopware/feat/backport
merge back
2 parents 506d66a + dec1db8 commit 20f1fe8

303 files changed

Lines changed: 23766 additions & 3067 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ dump.sql*
2323
.devenv*
2424
devenv.local.nix
2525

26+
# mise local overrides
27+
/mise.local.toml
28+
/.mise.local.toml
29+
2630
/.direnv
2731
/env-bridge/env-bridge
2832

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ linters:
3939
- gocheckcompilerdirectives
4040
- godox
4141
- nilnil
42+
- perfsprint
4243
exclusions:
4344
rules:
4445
- path: cmd\/*

CONTRIBUTING.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,39 @@ golangci-lint run ./...
4444

4545
Add or update tests for bug fixes and new behavior.
4646

47+
### Using mise
48+
49+
This repository includes a `mise.toml` file for managing the recommended Go
50+
and golangci-lint versions and for providing convenient development tasks.
51+
52+
After installing mise, set up the project tools with:
53+
54+
```sh
55+
mise install
56+
```
57+
58+
You can then run the complete local check suite with:
59+
60+
```sh
61+
mise run check
62+
```
63+
64+
Individual tasks are also available:
65+
66+
```sh
67+
mise run format # Format Go source files
68+
mise run format-check # Check Go formatting (gofmt and gci) without changing files
69+
mise run build # Build the shopware-cli binary
70+
mise run test # Run the network-isolated test suite (Linux/macOS only)
71+
mise run test-unit # Run Go tests without the sandbox wrapper (works everywhere)
72+
mise run vet # Run go vet
73+
mise run lint # Run golangci-lint
74+
```
75+
76+
For machine-specific settings, create `mise.local.toml`. This file is ignored
77+
by Git and should not contain secrets that belong in a dedicated secret
78+
manager.
79+
4780
## Reviews
4881

4982
Maintainers may ask for changes, suggest a different direction, or decline a PR if the approach was not discussed beforehand. That is not personal; it is how we keep the project consistent and sustainable.

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,24 @@ If you need CI-friendly behavior, disable prompts:
7575
shopware-cli --no-interaction <command>
7676
```
7777

78+
Silence update notifications for a single command:
79+
80+
```bash
81+
shopware-cli --no-update-hint
82+
```
83+
84+
## Configuration
85+
86+
### Disable update notifications
87+
88+
To disable update notifications for the current shell session, set:
89+
90+
```bash
91+
export SHOPWARE_CLI_NO_UPDATE_NOTIFICATION=true
92+
```
93+
94+
To make the setting **persistent**, add the export command to your shell profile, such as `~/.bashrc` or `~/.zshrc`.
95+
7896
## Repository Layout
7997

8098
- `cmd/`: Cobra command groups for account, extension, and project workflows

cmd/extension/extension_admin_watch.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ var extensionAdminWatchCmd = &cobra.Command{
7777
cfgs := extension.BuildAssetConfigFromExtensions(cmd.Context(), sources, extension.AssetBuildConfig{}).FilterByAdmin()
7878

7979
if len(cfgs) == 0 {
80-
return fmt.Errorf("found nothing to compile")
80+
return errors.New("found nothing to compile")
8181
}
8282

8383
if _, err := extension.InstallNodeModulesOfConfigs(cmd.Context(), cfgs, extension.AssetBuildConfig{}); err != nil {
@@ -125,7 +125,7 @@ var extensionAdminWatchCmd = &cobra.Command{
125125
listenSplit := strings.Split(adminWatchListen, ":")
126126

127127
if len(listenSplit) != 2 {
128-
return fmt.Errorf("listen should contain a colon")
128+
return errors.New("listen should contain a colon")
129129
}
130130

131131
if len(adminWatchURL) == 0 {
@@ -184,7 +184,7 @@ var extensionAdminWatchCmd = &cobra.Command{
184184

185185
// Modify admin url index page to load anything from our watcher
186186
if req.URL.Path == targetShopUrl.Path+"/admin" {
187-
resp, err := http.Get(fmt.Sprintf("%s/admin", targetShopUrl.Scheme+schemeHostSeparator+targetShopUrl.Host))
187+
resp, err := http.Get(targetShopUrl.Scheme + schemeHostSeparator + targetShopUrl.Host + "/admin")
188188
if err != nil {
189189
logging.FromContext(cmd.Context()).Errorf("proxy failed %v", err)
190190
w.WriteHeader(http.StatusInternalServerError)

cmd/extension/extension_config_init.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package extension
22

33
import (
4-
"fmt"
4+
"errors"
55
"path/filepath"
66

77
"charm.land/huh/v2"
@@ -44,15 +44,15 @@ Examples:
4444
form := huh.NewForm(
4545
huh.NewGroup(
4646
huh.NewConfirm().
47-
Title(fmt.Sprintf("%s already exists. Overwrite?", extension.ConfigFileName)).
47+
Title(extension.ConfigFileName + " already exists. Overwrite?").
4848
Value(&overwrite),
4949
),
5050
)
5151
if err := form.Run(); err != nil {
5252
return err
5353
}
5454
if !overwrite {
55-
return fmt.Errorf("aborted: config already exists (pass --force to overwrite)")
55+
return errors.New("aborted: config already exists (pass --force to overwrite)")
5656
}
5757
force = true
5858
}

cmd/extension/extension_fix.go

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

33
import (
4+
"errors"
45
"fmt"
56
"os"
67
"path/filepath"
@@ -25,7 +26,7 @@ var extensionFixCmd = &cobra.Command{
2526

2627
if !allowNonGit {
2728
if stat, err := os.Stat(filepath.Join(args[0], ".git")); err != nil || !stat.IsDir() {
28-
return fmt.Errorf("provided folder is not a git repository. Use --allow-non-git flag to run anyway")
29+
return errors.New("provided folder is not a git repository. Use --allow-non-git flag to run anyway")
2930
}
3031
}
3132

cmd/extension/extension_package.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ var extensionPackageCmd = &cobra.Command{
191191
if len(fileName) == 0 {
192192
fileName = fmt.Sprintf("%s-%s.zip", name, tag)
193193
if len(tag) == 0 {
194-
fileName = fmt.Sprintf("%s.zip", name)
194+
fileName = name + ".zip"
195195
}
196196
}
197197

@@ -247,8 +247,8 @@ func getStringOnStringError(val string, _ error) string {
247247

248248
func executeHooks(ctx context.Context, ext extension.Extension, hooks []string, extDir string) error {
249249
env := []string{
250-
fmt.Sprintf("EXTENSION_DIR=%s", extDir),
251-
fmt.Sprintf("ORIGINAL_EXTENSION_DIR=%s", ext.GetPath()),
250+
"EXTENSION_DIR=" + extDir,
251+
"ORIGINAL_EXTENSION_DIR=" + ext.GetPath(),
252252
}
253253

254254
for _, hook := range hooks {

cmd/project/ci.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package project
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"os"
89
"os/exec"
@@ -423,7 +424,7 @@ func projectCISafetyCheck(ctx context.Context, root string, force bool, getenv f
423424
}
424425

425426
if dirty {
426-
return fmt.Errorf("project ci removes source files and creates build stubs; refusing to run outside CI with a dirty git working tree. Commit, stash, or clean local changes, or pass --force if you intentionally want to run it")
427+
return errors.New("project ci removes source files and creates build stubs; refusing to run outside CI with a dirty git working tree. Commit, stash, or clean local changes, or pass --force if you intentionally want to run it")
427428
}
428429

429430
logging.FromContext(ctx).Warnf("Running project ci outside a CI environment; this command removes source files and should usually only be used in CI")
@@ -504,7 +505,7 @@ func executeCIHooks(ctx context.Context, sectionName string, hooks []string, roo
504505
hookCmd.Stdout = os.Stdout
505506
hookCmd.Stderr = os.Stderr
506507
hookCmd.Dir = root
507-
hookCmd.Env = append(os.Environ(), fmt.Sprintf("PROJECT_ROOT=%s", root))
508+
hookCmd.Env = append(os.Environ(), "PROJECT_ROOT="+root)
508509

509510
if err := hookCmd.Run(); err != nil {
510511
return fmt.Errorf("hook failed (%s): %w", hook, err)

cmd/project/executor.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package project
22

33
import (
4+
"database/sql"
5+
46
"github.com/spf13/cobra"
57

68
"github.com/shopware/shopware-cli/internal/executor"
@@ -21,3 +23,36 @@ func resolveExecutor(cmd *cobra.Command, projectRoot string) (executor.Executor,
2123

2224
return executor.New(projectRoot, envCfg, cfg)
2325
}
26+
27+
// resolveProjectDatabaseConnection resolves the database credentials of the
28+
// current environment through its executor.
29+
func resolveProjectDatabaseConnection(cmd *cobra.Command) (*executor.DatabaseConnection, error) {
30+
projectRoot, err := findClosestShopwareProject()
31+
if err != nil {
32+
return nil, err
33+
}
34+
35+
cmdExecutor, err := resolveExecutor(cmd, projectRoot)
36+
if err != nil {
37+
return nil, err
38+
}
39+
40+
return cmdExecutor.DatabaseConnection(cmd.Context())
41+
}
42+
43+
// connectProjectDatabase resolves the database of the current environment and
44+
// opens a single dedicated connection to it. The returned cleanup closes
45+
// connection and pool.
46+
func connectProjectDatabase(cmd *cobra.Command) (*sql.Conn, *executor.DatabaseConnection, func(), error) {
47+
dbConn, err := resolveProjectDatabaseConnection(cmd)
48+
if err != nil {
49+
return nil, nil, nil, err
50+
}
51+
52+
conn, cleanup, err := dbConn.Open(cmd.Context())
53+
if err != nil {
54+
return nil, nil, nil, err
55+
}
56+
57+
return conn, dbConn, cleanup, nil
58+
}

0 commit comments

Comments
 (0)