Skip to content

Commit 35ea3d8

Browse files
committed
Renamed Config.Save to SaveName for clarity.
1 parent 67427d6 commit 35ea3d8

File tree

5 files changed

+36
-35
lines changed

5 files changed

+36
-35
lines changed

lib/example_posix_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ import (
1010

1111
func ExampleConfig_clean() {
1212
c := Config{
13-
Save: "..//test///.",
13+
SaveName: "..//test///.",
1414
}
1515
if err := c.clean(); err != nil {
1616
log.Fatalln(err)
1717
}
18-
fmt.Print(c.Save)
18+
fmt.Print(c.SaveName)
1919
// Output: ../test
2020
}
2121

lib/log.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (c *Config) WriteLog(s string) {
5959
if !c.Dupes {
6060
l += fmt.Sprintf("hashes: %s; ", humanize.Bytes(uint64(len(c.hashes)*32)))
6161
}
62-
if c.Save != "" {
62+
if c.SaveName != "" {
6363
l += fmt.Sprintf("names: %s; ", humanize.Bytes(uint64(c.names)))
6464
}
6565
l += fmt.Sprintf("%s\n", s)

lib/zipcmt.go

+18-17
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
type Config struct {
2525
Dirs []string
26-
Save string // rename to SaveName
26+
SaveName string
2727
Dupes bool
2828
Export bool
2929
Log bool
@@ -197,8 +197,8 @@ func (c *Config) WalkDir(root string) error {
197197
c.saved++
198198
}
199199
}
200-
if c.Save != "" {
201-
dat.name = c.exports.unique(path, c.Save)
200+
if c.SaveName != "" {
201+
dat.name = c.exports.unique(path, c.SaveName)
202202
c.names += len(dat.name)
203203
if c.save(dat) {
204204
c.WriteLog(fmt.Sprintf("SAVED: %s (%s) << %s", dat.name, humanize.Bytes(uint64(len(cmmt))), path))
@@ -212,32 +212,33 @@ func (c *Config) WalkDir(root string) error {
212212

213213
// clean the syntax of the target export directory path.
214214
func (c *Config) clean() error {
215-
if c.Save != "" {
216-
c.Save = filepath.Clean(c.Save)
217-
p := strings.Split(c.Save, string(filepath.Separator))
215+
if name := c.SaveName; name != "" {
216+
name = filepath.Clean(name)
217+
p := strings.Split(name, string(filepath.Separator))
218218
if p[0] == "~" {
219219
hd, err := os.UserHomeDir()
220220
if err != nil {
221221
return err
222222
}
223-
c.Save = strings.Replace(c.Save, "~", hd, 1)
223+
name = strings.Replace(name, "~", hd, 1)
224224
}
225-
s, err := os.Stat(c.Save)
225+
s, err := os.Stat(name)
226226
if errors.Is(err, fs.ErrInvalid) {
227-
return fmt.Errorf("%s: export %w", c.Save, ErrValid)
227+
return fmt.Errorf("%s: export %w", name, ErrValid)
228228
}
229229
if errors.Is(err, fs.ErrNotExist) {
230-
return fmt.Errorf("%s: export %w", c.Save, ErrMissing)
230+
return fmt.Errorf("%s: export %w", name, ErrMissing)
231231
}
232232
if errors.Is(err, fs.ErrPermission) {
233-
return fmt.Errorf("%s: export %w", c.Save, ErrPerm)
233+
return fmt.Errorf("%s: export %w", name, ErrPerm)
234234
}
235235
if err != nil {
236-
return fmt.Errorf("%s: export %w", c.Save, err)
236+
return fmt.Errorf("%s: export %w", name, err)
237237
}
238238
if !s.IsDir() {
239-
return fmt.Errorf("%s: export %w", c.Save, ErrIsFile)
239+
return fmt.Errorf("%s: export %w", name, ErrIsFile)
240240
}
241+
c.SaveName = name
241242
}
242243
return nil
243244
}
@@ -288,7 +289,7 @@ func (c Config) separator(name string) string {
288289
// Status summarizes the zip files scan.
289290
func (c Config) Status() string {
290291
if c.Log {
291-
if c.Save != "" {
292+
if c.SaveName != "" {
292293
s := fmt.Sprintf("Saved %d comments from %d finds", c.saved, c.cmmts)
293294
c.WriteLog(s)
294295
}
@@ -314,7 +315,7 @@ func (c Config) Status() string {
314315
}
315316
s += color.Secondary.Sprint("Scanned ") +
316317
color.Primary.Sprintf("%d zip %s", c.zips, a)
317-
if c.Save != "" && c.saved != c.cmmts {
318+
if c.SaveName != "" && c.saved != c.cmmts {
318319
s += color.Secondary.Sprint(", saved ") +
319320
color.Primary.Sprintf("%d text files", c.saved)
320321
}
@@ -327,7 +328,7 @@ func (c Config) Status() string {
327328
return s
328329
}
329330

330-
// Save a zip cmmt to the file path.
331+
// SaveName a zip cmmt to the file path.
331332
// Unless the overwrite argument is set, any previous cmmt text files are skipped.
332333
func (c *Config) save(dat save) bool {
333334
// name, cmmt string, mod time.Time, ow bool
@@ -387,7 +388,7 @@ func valid(name string) bool {
387388
// unique checks the destination path against an export map.
388389
// The map contains a unique collection of previously used destination
389390
// paths, to avoid creating duplicate text filenames while using the
390-
// Save config.
391+
// SaveName config.
391392
func (e export) unique(zipPath, dest string) string {
392393
base := filepath.Base(zipPath)
393394
name := strings.TrimSuffix(base, filepath.Ext(base)) + filename

lib/zipcmt_test.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212

1313
func TestConfig_Clean(t *testing.T) {
1414
type fields struct {
15-
Save string
15+
SaveName string
1616
Export bool
1717
Dupes bool
1818
Overwrite bool
@@ -28,15 +28,15 @@ func TestConfig_Clean(t *testing.T) {
2828
wantErr bool
2929
}{
3030
{"empty", fields{}, false},
31-
{"missing", fields{Save: "/no/such/directory"}, true},
32-
{"file", fields{Save: "../test/test.txt"}, true},
33-
{"dir", fields{Save: "../test"}, false},
34-
{"home", fields{Save: "~"}, false},
31+
{"missing", fields{SaveName: "/no/such/directory"}, true},
32+
{"file", fields{SaveName: "../test/test.txt"}, true},
33+
{"dir", fields{SaveName: "../test"}, false},
34+
{"home", fields{SaveName: "~"}, false},
3535
}
3636
for _, tt := range tests {
3737
t.Run(tt.name, func(t *testing.T) {
3838
c := &Config{
39-
Save: tt.fields.Save,
39+
SaveName: tt.fields.SaveName,
4040
Export: tt.fields.Export,
4141
Dupes: tt.fields.Dupes,
4242
Overwrite: tt.fields.Overwrite,
@@ -91,7 +91,7 @@ func Test_Read(t *testing.T) {
9191

9292
func TestConfig_Scans(t *testing.T) {
9393
type fields struct {
94-
Save string
94+
SaveName string
9595
Export bool
9696
Dupes bool
9797
Overwrite bool
@@ -115,12 +115,12 @@ func TestConfig_Scans(t *testing.T) {
115115
{"no root", fields{}, "", true},
116116
{"bad root", fields{}, "../test/missing", true},
117117
{"test dir", fields{Dupes: true}, "../test", false},
118-
{"exportdir", fields{Dupes: true, Save: tmp}, "../test", false},
118+
{"exportdir", fields{Dupes: true, SaveName: tmp}, "../test", false},
119119
}
120120
for _, tt := range tests {
121121
t.Run(tt.name, func(t *testing.T) {
122122
c := &Config{
123-
Save: tt.fields.Save,
123+
SaveName: tt.fields.SaveName,
124124
Export: tt.fields.Export,
125125
Dupes: tt.fields.Dupes,
126126
Overwrite: tt.fields.Overwrite,
@@ -139,7 +139,7 @@ func TestConfig_Scans(t *testing.T) {
139139

140140
func TestConfig_separator(t *testing.T) {
141141
type fields struct {
142-
Save string
142+
SaveName string
143143
Export bool
144144
Dupes bool
145145
Overwrite bool
@@ -162,7 +162,7 @@ func TestConfig_separator(t *testing.T) {
162162
for _, tt := range tests {
163163
t.Run(tt.name, func(t *testing.T) {
164164
c := Config{
165-
Save: tt.fields.Save,
165+
SaveName: tt.fields.SaveName,
166166
Export: tt.fields.Export,
167167
Dupes: tt.fields.Dupes,
168168
Overwrite: tt.fields.Overwrite,
@@ -182,7 +182,7 @@ func TestConfig_separator(t *testing.T) {
182182
func TestConfig_Status(t *testing.T) {
183183
color.Enable = false
184184
type fields struct {
185-
Save string
185+
SaveName string
186186
Export bool
187187
Dupes bool
188188
Overwrite bool
@@ -204,7 +204,7 @@ func TestConfig_Status(t *testing.T) {
204204
for _, tt := range tests {
205205
t.Run(tt.name, func(t *testing.T) {
206206
c := Config{
207-
Save: tt.fields.Save,
207+
SaveName: tt.fields.SaveName,
208208
Export: tt.fields.Export,
209209
Dupes: tt.fields.Dupes,
210210
Overwrite: tt.fields.Overwrite,

main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func main() {
4242
flag.BoolVar(&c.Overwrite, "overwrite", false, "overwrite any previously exported comment text files")
4343
flag.BoolVar(&c.Quiet, "quiet", false, "suppress zipcmt feedback except for errors")
4444
flag.BoolVar(&c.Raw, "raw", false, "use the original comment text encoding (CP437, ISO-8859"+ellipsis+") instead of Unicode")
45-
flag.StringVar(&c.Save, "save", "", "save the comments to uniquely named textfiles in this directory")
45+
flag.StringVar(&c.SaveName, "save", "", "save the comments to uniquely named textfiles in this directory")
4646
ver := flag.Bool("version", false, "version and information for this program")
4747
a := flag.Bool("a", false, "alias for all")
4848
o := flag.Bool("o", false, "alias for overwrite")
@@ -66,7 +66,7 @@ func main() {
6666
c.Print = true
6767
}
6868
if *s != "" {
69-
c.Save = *s
69+
c.SaveName = *s
7070
}
7171
if *o {
7272
c.Overwrite = true

0 commit comments

Comments
 (0)