Skip to content

Commit 0b14054

Browse files
committed
feat: update POC
1 parent 6fb922a commit 0b14054

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

pkg/experimental/commands/.mygcl.reference.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
version: v1.56.2
22
name: custom-golangci-lint # optional, default: gcl-custom
3+
destination: ./my/path/ # optional, default: .
34
plugins:
45
# a plugin from a Go proxy
56
- module: 'github.com/example/plugin3'

pkg/experimental/commands/custom/internal/builder.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,14 @@ func (b Builder) copyBinary(binaryName string) error {
178178
return fmt.Errorf("stat source file: %w", err)
179179
}
180180

181-
dst, err := os.OpenFile(filepath.Clean(binaryName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, info.Mode())
181+
if b.cfg.Destination != "" {
182+
err = os.MkdirAll(b.cfg.Destination, os.ModePerm)
183+
if err != nil {
184+
return fmt.Errorf("create destination directory: %w", err)
185+
}
186+
}
187+
188+
dst, err := os.OpenFile(filepath.Join(b.cfg.Destination, binaryName), os.O_RDWR|os.O_CREATE|os.O_TRUNC, info.Mode())
182189
if err != nil {
183190
return fmt.Errorf("create destination file: %w", err)
184191
}

pkg/experimental/commands/custom/internal/configuration.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ type Configuration struct {
2323
// Name of the binary.
2424
Name string `yaml:"name,omitempty"`
2525

26+
// Destination is the path to a directory to store the binary.
27+
Destination string `yaml:"destination,omitempty"`
28+
2629
// Plugins information.
2730
Plugins []*Plugin `yaml:"plugins,omitempty"`
2831
}

pkg/experimental/commands/custom/internal/imports.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
func (b Builder) updatePluginsFile() error {
2323
importsDest := filepath.Join(b.repo, "cmd", "golangci-lint", "plugins.go")
2424

25-
_, err := os.Stat(importsDest)
25+
info, err := os.Stat(importsDest)
2626
if err != nil {
2727
return fmt.Errorf("file %s not found: %w", importsDest, err)
2828
}
@@ -34,14 +34,7 @@ func (b Builder) updatePluginsFile() error {
3434

3535
b.log.Infof("generated imports info %s:\n%s\n", importsDest, source)
3636

37-
file, err := os.Open(filepath.Clean(importsDest))
38-
if err != nil {
39-
return fmt.Errorf("open file %s: %w", importsDest, err)
40-
}
41-
42-
defer func() { _ = file.Close() }()
43-
44-
_, err = file.Write(source)
37+
err = os.WriteFile(filepath.Clean(importsDest), source, info.Mode())
4538
if err != nil {
4639
return fmt.Errorf("write file %s: %w", importsDest, err)
4740
}

pkg/experimental/commands/mygcl.schema.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
"type": "string",
1313
"description": "Name of the binary."
1414
},
15+
"destination": {
16+
"type": "string",
17+
"description": "Destination is the path to a directory to store the binary."
18+
},
1519
"plugins": {
1620
"items": {
1721
"$ref": "#/$defs/Plugin"
@@ -69,4 +73,4 @@
6973
}
7074
},
7175
"description": "mygcl configuration definition file"
72-
}
76+
}

0 commit comments

Comments
 (0)