Skip to content

Commit

Permalink
Add list switch to exists
Browse files Browse the repository at this point in the history
  • Loading branch information
triole committed Aug 11, 2024
1 parent a9097cd commit e9a5c6a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/argparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var CLI struct {

Ex struct {
NumberRange string `help:"number of files to be considered a valid match, check is successful if the number of matched files is in the expected range, arg is a string of one or two comma separated values (min and max), e.g. '1' requires exactly one match, '1,5' represents the range between 1 and 5, '1,0' is default meaning any number of matches higher than one will do" short:"b" default:"1,0"`
List bool `help:"list all processed files" short:"l"`
} `cmd:"" help:"check if file(s) exists, return non-zero exitcode if not"`

Rt struct {
Expand Down
1 change: 1 addition & 0 deletions src/conf/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ func Init(cli interface{}, lg logseal.Logseal) (conf Conf) {
conf.Exists.MinNumber, conf.Exists.MaxNumber = parseNumberRangeArg(
getcli(cli, "Ex.NumberRange").(string), lg,
)
conf.Exists.List = getcli(cli, "Ex.List").(bool)
conf.Remove.Yes = getcli(cli, "Rm.Yes").(bool)
conf.Rotate.CompressionFormat = getcli(cli, "Rt.Format").(string)
conf.Rotate.SkipTruncate = getcli(cli, "Rt.SkipTruncate").(bool)
Expand Down
1 change: 1 addition & 0 deletions src/conf/struct.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type tLs struct {
type tExists struct {
MinNumber int
MaxNumber int
List bool
}

type tCopyMove struct {
Expand Down
8 changes: 8 additions & 0 deletions src/fileaxe/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ func (fa FileAxe) list(fileList FileInfos) {
func (fa FileAxe) exists(fileList FileInfos) {
match_no := len(fileList)
success := fa.isInRange(match_no, fa.Conf.Exists.MinNumber, fa.Conf.Exists.MaxNumber)
if match_no > 0 && fa.Conf.Exists.List {
for _, el := range fileList {
fa.Lg.Info(
el.Path,
logseal.F{"age": el.Age, "lastmod": el.LastMod},
)
}
}
fa.Lg.Info(
"exists check results",
logseal.F{
Expand Down

0 comments on commit e9a5c6a

Please sign in to comment.