Skip to content

Commit 8ae3f4a

Browse files
committed
Broke out Config flags to internal.
1 parent 73245c8 commit 8ae3f4a

File tree

4 files changed

+39
-27
lines changed

4 files changed

+39
-27
lines changed

lib/example_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ func ExampleRead() {
2525
}
2626

2727
func ExampleConfig_Status() {
28-
c := Config{
29-
test: true,
30-
}
28+
c := Config{}
29+
c.SetTest()
3130
if err := c.WalkDir("../test"); err != nil {
3231
log.Panicln(err)
3332
}
3433
fmt.Print(c.Status())
3534

3635
c = Config{
3736
Dupes: true,
38-
test: true,
3937
}
38+
c.SetTest()
4039
if err := c.WalkDir("../test"); err != nil {
4140
log.Panicln(err)
4241
}

lib/zipcmt.go

+26-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import (
2222
)
2323

2424
type Config struct {
25-
Timer time.Time
2625
Dirs []string
2726
Save string
2827
LogName string
@@ -35,13 +34,30 @@ type Config struct {
3534
Raw bool
3635
Print bool
3736
Quiet bool
38-
test bool
39-
zips int
40-
cmmts int
41-
names int
42-
saved int
43-
exports export
44-
hashes hash
37+
internal
38+
}
39+
40+
type internal struct {
41+
test bool
42+
zips int
43+
cmmts int
44+
names int
45+
saved int
46+
exports export
47+
hashes hash
48+
timer time.Time
49+
}
50+
51+
func (i *internal) SetTest() {
52+
i.test = true
53+
}
54+
55+
func (i *internal) SetTimer() {
56+
i.timer = time.Now()
57+
}
58+
59+
func (i *internal) Timer() time.Duration {
60+
return time.Since(i.timer)
4561
}
4662

4763
type (
@@ -263,7 +279,7 @@ func (c Config) Status() string {
263279
s := fmt.Sprintf("Saved %d comments from %d finds", c.saved, c.cmmts)
264280
c.WriteLog(s)
265281
}
266-
s := fmt.Sprintf("Scan finished, time taken: %s", time.Since(c.Timer))
282+
s := fmt.Sprintf("Scan finished, time taken: %s", c.Timer())
267283
c.WriteLog(s)
268284
}
269285
if c.Quiet {
@@ -293,7 +309,7 @@ func (c Config) Status() string {
293309
color.Primary.Sprintf("%d %s%s", c.cmmts, unq, cm)
294310
if !c.test {
295311
s += color.Secondary.Sprint(", taking ") +
296-
color.Primary.Sprintf("%s", time.Since(c.Timer)) + "\n"
312+
color.Primary.Sprintf("%s", c.Timer()) + "\n"
297313
}
298314
return s
299315
}

lib/zipcmt_test.go

+9-11
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ func TestConfig_Clean(t *testing.T) {
4343
Raw: tt.fields.Raw,
4444
Print: tt.fields.Print,
4545
Quiet: tt.fields.Quiet,
46-
zips: tt.fields.zips,
47-
cmmts: tt.fields.cmmts,
4846
}
47+
c.zips = tt.fields.zips
48+
c.cmmts = tt.fields.cmmts
4949
if err := c.clean(); (err != nil) != tt.wantErr {
5050
t.Errorf("Config.cean() error = %v, wantErr %v", err, tt.wantErr)
5151
}
@@ -62,8 +62,6 @@ func Test_Read(t *testing.T) {
6262
Raw bool
6363
Print bool
6464
Quiet bool
65-
zips int
66-
cmmts int
6765
}
6866
tests := []struct {
6967
name string
@@ -129,9 +127,9 @@ func TestConfig_Scans(t *testing.T) {
129127
Raw: tt.fields.Raw,
130128
Print: tt.fields.Print,
131129
Quiet: tt.fields.Quiet,
132-
zips: tt.fields.zips,
133-
cmmts: tt.fields.cmmts,
134130
}
131+
c.zips = tt.fields.zips
132+
c.cmmts = tt.fields.cmmts
135133
if err := c.WalkDir(tt.root); (err != nil) != tt.wantErr {
136134
t.Errorf("Config.Scans() error = %v, wantErr %v", err, tt.wantErr)
137135
}
@@ -171,9 +169,9 @@ func TestConfig_separator(t *testing.T) {
171169
Raw: tt.fields.Raw,
172170
Print: tt.fields.Print,
173171
Quiet: tt.fields.Quiet,
174-
zips: tt.fields.zips,
175-
cmmts: tt.fields.cmmts,
176172
}
173+
c.zips = tt.fields.zips
174+
c.cmmts = tt.fields.cmmts
177175
if got := strings.TrimSpace(c.separator(tt.fname)); got != tt.want {
178176
t.Errorf("Config.separator() = %v, want %v", got, tt.want)
179177
}
@@ -213,10 +211,10 @@ func TestConfig_Status(t *testing.T) {
213211
Raw: tt.fields.Raw,
214212
Print: tt.fields.Print,
215213
Quiet: tt.fields.Quiet,
216-
test: true,
217-
zips: tt.fields.zips,
218-
cmmts: tt.fields.cmmts,
219214
}
215+
c.zips = tt.fields.zips
216+
c.cmmts = tt.fields.cmmts
217+
c.SetTest()
220218
if got := strings.TrimSpace(c.Status()); got != tt.want {
221219
t.Errorf("Config.Status() = \ngot: %v,\nwant: %v", got, tt.want)
222220
}

main.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"runtime"
1212
"strings"
1313
"text/tabwriter"
14-
"time"
1514

1615
zipcmt "github.com/bengarrett/zipcmt/lib"
1716
"github.com/gookit/color"
@@ -32,7 +31,7 @@ func main() {
3231
const ellipsis = "\u2026"
3332
var c zipcmt.Config
3433
var noprint bool
35-
c.Timer = time.Now()
34+
c.SetTimer()
3635
flag.BoolVar(&noprint, "noprint", false, "do not print comments to the terminal to improve the performance of the scan")
3736
flag.BoolVar(&c.NoWalk, "norecursive", false, "do not recursively walk through any subdirectories while scanning for zip archives")
3837
flag.BoolVar(&c.Export, "export", false, fmt.Sprintf("save the comments as text files stored alongside the zip files (%s)",

0 commit comments

Comments
 (0)