@@ -10,76 +10,34 @@ import (
1010 "github.com/vladopajic/go-test-coverage/v2/pkg/testcoverage"
1111)
1212
13- const (
14- // default value of string variables passed by CI
15- ciDefaultString = `***`
16- // default value of int variables passed by CI
17- ciDefaultInt = - 1
18- )
19-
2013type args struct {
21- ConfigPath string `arg:"-c,--config"`
22- Profile string `arg:"-p,--profile" help:"path to coverage profile"`
23- Debug bool `arg:"-d,--debug"`
24- LocalPrefix string `arg:"-l,--local-prefix"` // deprecated
25- SourceDir string `arg:"-s,--source-dir"`
26- GithubActionOutput bool `arg:"-o,--github-action-output"`
27- ThresholdFile int `arg:"-f,--threshold-file"`
28- ThresholdPackage int `arg:"-k,--threshold-package"`
29- ThresholdTotal int `arg:"-t,--threshold-total"`
30-
31- BreakdownFileName string `arg:"--breakdown-file-name"`
32- DiffBaseBreakdownFileName string `arg:"--diff-base-breakdown-file-name"`
33-
34- BadgeFileName string `arg:"-b,--badge-file-name"`
35-
36- CDNKey string `arg:"--cdn-key"`
37- CDNSecret string `arg:"--cdn-secret"`
38- CDNRegion string `arg:"--cdn-region"`
39- CDNEndpoint string `arg:"--cdn-endpoint"`
40- CDNFileName string `arg:"--cdn-file-name"`
41- CDNBucketName string `arg:"--cdn-bucket-name"`
42- CDNForcePathStyle bool `arg:"--cdn-force-path-style"`
43-
44- GitToken string `arg:"--git-token"`
45- GitRepository string `arg:"--git-repository"`
46- GitBranch string `arg:"--git-branch"`
47- GitFileName string `arg:"--git-file-name"`
48- }
49-
50- func newArgs () args {
51- return args {
52- ConfigPath : ciDefaultString ,
53- Profile : ciDefaultString ,
54- Debug : false ,
55- LocalPrefix : ciDefaultString ,
56- SourceDir : ciDefaultString ,
57- GithubActionOutput : false ,
58- ThresholdFile : ciDefaultInt ,
59- ThresholdPackage : ciDefaultInt ,
60- ThresholdTotal : ciDefaultInt ,
61-
62- BreakdownFileName : ciDefaultString ,
63- DiffBaseBreakdownFileName : ciDefaultString ,
64-
65- // Badge
66- BadgeFileName : ciDefaultString ,
67-
68- // CDN
69- CDNKey : ciDefaultString ,
70- CDNSecret : ciDefaultString ,
71- CDNRegion : ciDefaultString ,
72- CDNEndpoint : ciDefaultString ,
73- CDNFileName : ciDefaultString ,
74- CDNBucketName : ciDefaultString ,
75- CDNForcePathStyle : false ,
76-
77- // Git
78- GitToken : ciDefaultString ,
79- GitRepository : ciDefaultString ,
80- GitBranch : ciDefaultString ,
81- GitFileName : ciDefaultString ,
82- }
14+ ConfigPath * string `arg:"-c,--config"`
15+ Profile * string `arg:"-p,--profile" help:"path to coverage profile"`
16+ Debug bool `arg:"-d,--debug"`
17+ LocalPrefix * string `arg:"-l,--local-prefix"` // deprecated
18+ SourceDir * string `arg:"-s,--source-dir"`
19+ GithubActionOutput bool `arg:"-o,--github-action-output"`
20+ ThresholdFile * int `arg:"-f,--threshold-file"`
21+ ThresholdPackage * int `arg:"-k,--threshold-package"`
22+ ThresholdTotal * int `arg:"-t,--threshold-total"`
23+
24+ BreakdownFileName * string `arg:"--breakdown-file-name"`
25+ DiffBaseBreakdownFileName * string `arg:"--diff-base-breakdown-file-name"`
26+
27+ BadgeFileName * string `arg:"-b,--badge-file-name"`
28+
29+ CDNKey * string `arg:"--cdn-key"`
30+ CDNSecret * string `arg:"--cdn-secret"`
31+ CDNRegion * string `arg:"--cdn-region"`
32+ CDNEndpoint * string `arg:"--cdn-endpoint"`
33+ CDNFileName * string `arg:"--cdn-file-name"`
34+ CDNBucketName * string `arg:"--cdn-bucket-name"`
35+ CDNForcePathStyle bool `arg:"--cdn-force-path-style"`
36+
37+ GitToken * string `arg:"--git-token"`
38+ GitRepository * string `arg:"--git-repository"`
39+ GitBranch * string `arg:"--git-branch"`
40+ GitFileName * string `arg:"--git-file-name"`
8341}
8442
8543func (* args ) Version () string {
@@ -88,8 +46,8 @@ func (*args) Version() string {
8846
8947//nolint:cyclop,maintidx,mnd,funlen // relax
9048func (a * args ) overrideConfig (cfg testcoverage.Config ) (testcoverage.Config , error ) {
91- if ! isCIDefaultString ( a .Profile ) {
92- cfg .Profile = a .Profile
49+ if a .Profile != nil {
50+ cfg .Profile = * a .Profile
9351 }
9452
9553 if a .Debug {
@@ -100,53 +58,53 @@ func (a *args) overrideConfig(cfg testcoverage.Config) (testcoverage.Config, err
10058 cfg .GithubActionOutput = true
10159 }
10260
103- if ! isCIDefaultString ( a .LocalPrefix ) {
104- cfg .LocalPrefixDeprecated = a .LocalPrefix
61+ if a .LocalPrefix != nil {
62+ cfg .LocalPrefixDeprecated = * a .LocalPrefix
10563 }
10664
107- if ! isCIDefaultString ( a .SourceDir ) {
108- cfg .SourceDir = a .SourceDir
65+ if a .SourceDir != nil {
66+ cfg .SourceDir = * a .SourceDir
10967 }
11068
111- if ! isCIDefaultInt ( a .ThresholdFile ) {
112- cfg .Threshold .File = a .ThresholdFile
69+ if a .ThresholdFile != nil {
70+ cfg .Threshold .File = * a .ThresholdFile
11371 }
11472
115- if ! isCIDefaultInt ( a .ThresholdPackage ) {
116- cfg .Threshold .Package = a .ThresholdPackage
73+ if a .ThresholdPackage != nil {
74+ cfg .Threshold .Package = * a .ThresholdPackage
11775 }
11876
119- if ! isCIDefaultInt ( a .ThresholdTotal ) {
120- cfg .Threshold .Total = a .ThresholdTotal
77+ if a .ThresholdTotal != nil {
78+ cfg .Threshold .Total = * a .ThresholdTotal
12179 }
12280
123- if ! isCIDefaultString ( a .BreakdownFileName ) {
124- cfg .BreakdownFileName = a .BreakdownFileName
81+ if a .BreakdownFileName != nil {
82+ cfg .BreakdownFileName = * a .BreakdownFileName
12583 }
12684
127- if ! isCIDefaultString ( a .DiffBaseBreakdownFileName ) {
128- cfg .Diff .BaseBreakdownFileName = a .DiffBaseBreakdownFileName
85+ if a .DiffBaseBreakdownFileName != nil {
86+ cfg .Diff .BaseBreakdownFileName = * a .DiffBaseBreakdownFileName
12987 }
13088
131- if ! isCIDefaultString ( a .BadgeFileName ) {
132- cfg .Badge .FileName = a .BadgeFileName
89+ if a .BadgeFileName != nil {
90+ cfg .Badge .FileName = * a .BadgeFileName
13391 }
13492
135- if ! isCIDefaultString ( a .CDNSecret ) {
136- cfg .Badge .CDN .Secret = a .CDNSecret
93+ if a .CDNSecret != nil {
94+ cfg .Badge .CDN .Secret = * a .CDNSecret
13795 cfg .Badge .CDN .Key = escapeCiDefaultString (a .CDNKey )
13896 cfg .Badge .CDN .Region = escapeCiDefaultString (a .CDNRegion )
13997 cfg .Badge .CDN .FileName = escapeCiDefaultString (a .CDNFileName )
14098 cfg .Badge .CDN .BucketName = escapeCiDefaultString (a .CDNBucketName )
14199 cfg .Badge .CDN .ForcePathStyle = a .CDNForcePathStyle
142100
143- if ! isCIDefaultString ( a .CDNEndpoint ) {
144- cfg .Badge .CDN .Endpoint = a .CDNEndpoint
101+ if a .CDNEndpoint != nil {
102+ cfg .Badge .CDN .Endpoint = * a .CDNEndpoint
145103 }
146104 }
147105
148- if ! isCIDefaultString ( a .GitToken ) {
149- cfg .Badge .Git .Token = a .GitToken
106+ if a .GitToken != nil {
107+ cfg .Badge .Git .Token = * a .GitToken
150108 cfg .Badge .Git .Branch = escapeCiDefaultString (a .GitBranch )
151109 cfg .Badge .Git .FileName = escapeCiDefaultString (a .GitFileName )
152110
@@ -163,14 +121,14 @@ func (a *args) overrideConfig(cfg testcoverage.Config) (testcoverage.Config, err
163121}
164122
165123func readConfig () (testcoverage.Config , error ) {
166- cmdArgs := newArgs ()
167- arg .MustParse (& cmdArgs )
124+ cmdArgs := & args {}
125+ arg .MustParse (cmdArgs )
168126
169127 cfg := testcoverage.Config {}
170128
171129 // Load config from file
172- if ! isCIDefaultString ( cmdArgs .ConfigPath ) {
173- err := testcoverage .ConfigFromFile (& cfg , cmdArgs .ConfigPath )
130+ if cmdArgs .ConfigPath != nil {
131+ err := testcoverage .ConfigFromFile (& cfg , * cmdArgs .ConfigPath )
174132 if err != nil {
175133 return testcoverage.Config {}, fmt .Errorf ("failed loading config from file: %w" , err )
176134 }
@@ -190,14 +148,10 @@ func readConfig() (testcoverage.Config, error) {
190148 return cfg , nil
191149}
192150
193- func isCIDefaultString (v string ) bool { return v == ciDefaultString }
194-
195- func isCIDefaultInt (v int ) bool { return v == ciDefaultInt }
196-
197- func escapeCiDefaultString (v string ) string {
198- if v == ciDefaultString {
151+ func escapeCiDefaultString (str * string ) string {
152+ if str == nil {
199153 return ""
200154 }
201155
202- return v
156+ return * str
203157}
0 commit comments