give variables names that are less bad

This commit is contained in:
Lilian Jónsdóttir 2024-07-28 19:02:11 -07:00
parent d2abc90638
commit 1ac1f1c01f

84
main.go
View file

@ -28,11 +28,13 @@ const (
var ( var (
loglvl string loglvl string
f *filter.Filter fltr *filter.Filter
o, b, a, g, p, m string onArg, beforeArg, afterArg string
sm, lg string globArg, patternArg string
ung, unp string unGlobArg, unPatternArg string
fo, do, sh, ni bool modeArg, minArg, maxArg string
filesOnlyArg, dirsOnlyArg bool
hiddenArg, noInterArg bool
askconfirm, all bool askconfirm, all bool
workdir, ogdir cli.Path workdir, ogdir cli.Path
recursive bool recursive bool
@ -90,12 +92,12 @@ var (
err error err error
) )
if f == nil { if fltr == nil {
md, e := filemode.Parse(m) md, e := filemode.Parse(modeArg)
if e != nil { if e != nil {
return e return e
} }
f, err = filter.New(o, b, a, g, p, ung, unp, fo, do, false, sm, lg, md) fltr, err = filter.New(onArg, beforeArg, afterArg, globArg, patternArg, unGlobArg, unPatternArg, filesOnlyArg, dirsOnlyArg, false, minArg, maxArg, md)
} }
if err != nil { if err != nil {
return err return err
@ -120,13 +122,13 @@ var (
mode modes.Mode mode modes.Mode
err error err error
) )
infiles, err = files.FindTrash(trashDir, ogdir, f) infiles, err = files.FindTrash(trashDir, ogdir, fltr)
if err != nil { if err != nil {
return err return err
} }
if len(infiles) <= 0 { if len(infiles) <= 0 {
var msg string var msg string
if f.Blank() { if fltr.Blank() {
msg = "trash is empty" msg = "trash is empty"
} else { } else {
msg = "no files to show" msg = "no files to show"
@ -164,26 +166,26 @@ var (
beforeCommands = func(ctx *cli.Context) (err error) { beforeCommands = func(ctx *cli.Context) (err error) {
// setup filter // setup filter
if f == nil { if fltr == nil {
md, e := filemode.Parse(m) md, e := filemode.Parse(modeArg)
if e != nil { if e != nil {
return e return e
} }
f, err = filter.New(o, b, a, g, p, ung, unp, fo, do, false, sm, lg, md, ctx.Args().Slice()...) fltr, err = filter.New(onArg, beforeArg, afterArg, globArg, patternArg, unGlobArg, unPatternArg, filesOnlyArg, dirsOnlyArg, false, minArg, maxArg, md, ctx.Args().Slice()...)
} }
log.Debugf("filter: %s", f.String()) log.Debugf("filter: %s", fltr.String())
return return
} }
beforeTrash = func(_ *cli.Context) (err error) { beforeTrash = func(_ *cli.Context) (err error) {
if f == nil { if fltr == nil {
md, e := filemode.Parse(m) md, e := filemode.Parse(modeArg)
if e != nil { if e != nil {
return e return e
} }
f, err = filter.New(o, b, a, g, p, ung, unp, fo, do, !sh, sm, lg, md) fltr, err = filter.New(onArg, beforeArg, afterArg, globArg, patternArg, unGlobArg, unPatternArg, filesOnlyArg, dirsOnlyArg, !hiddenArg, minArg, maxArg, md)
} }
log.Debugf("filter: %s", f.String()) log.Debugf("filter: %s", fltr.String())
return return
} }
@ -204,7 +206,7 @@ var (
file, e := files.NewDisk(arg) file, e := files.NewDisk(arg)
if e != nil || workdir != "" { if e != nil || workdir != "" {
log.Debugf("%s wasn't really a file", arg) log.Debugf("%s wasn't really a file", arg)
f.AddFileName(arg) fltr.AddFileName(arg)
continue continue
} }
files_to_trash = append(files_to_trash, file) files_to_trash = append(files_to_trash, file)
@ -213,7 +215,7 @@ var (
// if none of the args were files, then process find files based on filter // if none of the args were files, then process find files based on filter
if len(files_to_trash) == 0 { if len(files_to_trash) == 0 {
fls, err := files.FindDisk(workdir, recursive, f) fls, err := files.FindDisk(workdir, recursive, fltr)
if err != nil { if err != nil {
return err return err
} }
@ -222,7 +224,7 @@ var (
return nil return nil
} }
files_to_trash = append(files_to_trash, fls...) files_to_trash = append(files_to_trash, fls...)
selectall = !f.Blank() selectall = !fltr.Blank()
} }
selected, _, err := interactive.Select(files_to_trash, termwidth, termheight, false, selectall, false, workdir, modes.Trashing) selected, _, err := interactive.Select(files_to_trash, termwidth, termheight, false, selectall, false, workdir, modes.Trashing)
@ -248,11 +250,11 @@ var (
log.Debugf("searching in directory %s for files", trashDir) log.Debugf("searching in directory %s for files", trashDir)
// look for files // look for files
fls, err := files.FindTrash(trashDir, ogdir, f) fls, err := files.FindTrash(trashDir, ogdir, fltr)
var msg string var msg string
log.Debugf("filter '%s' is blark? %t in %s", f, f.Blank(), ogdir) log.Debugf("filter '%s' is blark? %t in %s", fltr, fltr.Blank(), ogdir)
if f.Blank() && ogdir == "" { if fltr.Blank() && ogdir == "" {
msg = "trash is empty" msg = "trash is empty"
} else { } else {
msg = "no files to show" msg = "no files to show"
@ -266,7 +268,7 @@ var (
} }
// display them // display them
_, _, err = interactive.Select(fls, termwidth, termheight, true, false, ni, workdir, modes.Listing) _, _, err = interactive.Select(fls, termwidth, termheight, true, false, noInterArg, workdir, modes.Listing)
return err return err
}, },
@ -282,7 +284,7 @@ var (
log.Debugf("searching in directory %s for files", trashDir) log.Debugf("searching in directory %s for files", trashDir)
// look for files // look for files
fls, err := files.FindTrash(trashDir, ogdir, f) fls, err := files.FindTrash(trashDir, ogdir, fltr)
if len(fls) == 0 { if len(fls) == 0 {
fmt.Println("no files to restore") fmt.Println("no files to restore")
return nil return nil
@ -310,7 +312,7 @@ var (
Flags: slices.Concat(cleanRestoreFlags, alreadyintrashFlags, filterFlags), Flags: slices.Concat(cleanRestoreFlags, alreadyintrashFlags, filterFlags),
Before: beforeCommands, Before: beforeCommands,
Action: func(ctx *cli.Context) error { Action: func(ctx *cli.Context) error {
fls, err := files.FindTrash(trashDir, ogdir, f) fls, err := files.FindTrash(trashDir, ogdir, fltr)
if len(fls) == 0 { if len(fls) == 0 {
fmt.Println("no files to clean") fmt.Println("no files to clean")
return nil return nil
@ -354,75 +356,75 @@ var (
Name: "match", Name: "match",
Usage: "operate on files matching regex `PATTERN`", Usage: "operate on files matching regex `PATTERN`",
Aliases: []string{"m"}, Aliases: []string{"m"},
Destination: &p, Destination: &patternArg,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "glob", Name: "glob",
Usage: "operate on files matching `GLOB`", Usage: "operate on files matching `GLOB`",
Aliases: []string{"g"}, Aliases: []string{"g"},
Destination: &g, Destination: &globArg,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "not-match", Name: "not-match",
Usage: "operate on files not matching regex `PATTERN`", Usage: "operate on files not matching regex `PATTERN`",
Aliases: []string{"M"}, Aliases: []string{"M"},
Destination: &unp, Destination: &unPatternArg,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "not-glob", Name: "not-glob",
Usage: "operate on files not matching `GLOB`", Usage: "operate on files not matching `GLOB`",
Aliases: []string{"G"}, Aliases: []string{"G"},
Destination: &ung, Destination: &unGlobArg,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "on", Name: "on",
Usage: "operate on files modified on `DATE`", Usage: "operate on files modified on `DATE`",
Aliases: []string{"O"}, Aliases: []string{"O"},
Destination: &o, Destination: &onArg,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "after", Name: "after",
Usage: "operate on files modified before `DATE`", Usage: "operate on files modified before `DATE`",
Aliases: []string{"A"}, Aliases: []string{"A"},
Destination: &a, Destination: &afterArg,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "before", Name: "before",
Usage: "operate on files modified after `DATE`", Usage: "operate on files modified after `DATE`",
Aliases: []string{"B"}, Aliases: []string{"B"},
Destination: &b, Destination: &beforeArg,
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "files-only", Name: "files-only",
Usage: "operate on files only", Usage: "operate on files only",
Aliases: []string{"F"}, Aliases: []string{"F"},
DisableDefaultText: true, DisableDefaultText: true,
Destination: &fo, Destination: &filesOnlyArg,
}, },
&cli.BoolFlag{ &cli.BoolFlag{
Name: "dirs-only", Name: "dirs-only",
Usage: "operate on directories only", Usage: "operate on directories only",
Aliases: []string{"D"}, Aliases: []string{"D"},
DisableDefaultText: true, DisableDefaultText: true,
Destination: &do, Destination: &dirsOnlyArg,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "min-size", Name: "min-size",
Usage: "operate on files larger than `SIZE`", Usage: "operate on files larger than `SIZE`",
Aliases: []string{"N"}, Aliases: []string{"N"},
Destination: &sm, Destination: &minArg,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "max-size", Name: "max-size",
Usage: "operate on files smaller than `SIZE`", Usage: "operate on files smaller than `SIZE`",
Aliases: []string{"X"}, Aliases: []string{"X"},
Destination: &lg, Destination: &maxArg,
}, },
&cli.StringFlag{ &cli.StringFlag{
Name: "mode", Name: "mode",
Usage: "operate on files matching mode `MODE`", Usage: "operate on files matching mode `MODE`",
Aliases: []string{"x"}, Aliases: []string{"x"},
Destination: &m, Destination: &modeArg,
}, },
} }
@ -446,7 +448,7 @@ var (
Usage: "operate on hidden files", Usage: "operate on hidden files",
Aliases: []string{"H"}, Aliases: []string{"H"},
DisableDefaultText: true, DisableDefaultText: true,
Destination: &sh, Destination: &hiddenArg,
}, },
} }
@ -464,7 +466,7 @@ var (
Name: "non-interactive", Name: "non-interactive",
Usage: "list files and quit", Usage: "list files and quit",
Aliases: []string{"n"}, Aliases: []string{"n"},
Destination: &ni, Destination: &noInterArg,
DisableDefaultText: true, DisableDefaultText: true,
}, },
} }