1
0
Fork 0
mirror of https://github.com/ethauvin/fail2ban-digest.git synced 2025-04-26 02:57:12 -07:00

use dest argument for add_subparser

Instead of setting the value of cmd arg by default use the dest
variable. Also check if no argument is given on command line
This commit is contained in:
Enrico Tagliavini 2017-05-15 16:55:20 +02:00
parent 3066a12a4f
commit c7ca780df8

View file

@ -160,6 +160,8 @@ def main(args):
print(digest(args.database, args.delete)[1]) print(digest(args.database, args.delete)[1])
elif args.cmd == 'maildigest': elif args.cmd == 'maildigest':
mail_digest(args.database, args.to, args.mail_from, args.delete) mail_digest(args.database, args.to, args.mail_from, args.delete)
elif args.cmd is None:
print('No action specified')
return return
if __name__ == '__main__': if __name__ == '__main__':
@ -169,7 +171,10 @@ if __name__ == '__main__':
description = 'Gather fail2ban events to process periodically and generate a digest', description = 'Gather fail2ban events to process periodically and generate a digest',
epilog = 'use `%s command --help\' to get help about a specific command' % progname, epilog = 'use `%s command --help\' to get help about a specific command' % progname,
) )
subparsers = parser.add_subparsers(title = 'available commands') subparsers = parser.add_subparsers(
title = 'available commands',
dest = 'cmd',
)
subcommands = {} subcommands = {}
sc = 'add' sc = 'add'
@ -187,7 +192,6 @@ if __name__ == '__main__':
type = ip_address, type = ip_address,
help = 'offending IP address, both IPv4 and IPv6 are accepted' help = 'offending IP address, both IPv4 and IPv6 are accepted'
) )
subcommands[sc].set_defaults(cmd = sc)
sc = 'digest' sc = 'digest'
subcommands[sc] = subparsers.add_parser( subcommands[sc] = subparsers.add_parser(
@ -204,7 +208,6 @@ if __name__ == '__main__':
default = False, default = False,
help = 'do / don\'t delete current database, next call to add will create a new empty one' help = 'do / don\'t delete current database, next call to add will create a new empty one'
) )
subcommands[sc].set_defaults(cmd = sc)
sc = 'maildigest' sc = 'maildigest'
subcommands[sc] = subparsers.add_parser( subcommands[sc] = subparsers.add_parser(
@ -233,7 +236,6 @@ if __name__ == '__main__':
default = 'root', default = 'root',
help = 'send email to specified user / address. Default is root' help = 'send email to specified user / address. Default is root'
) )
subcommands[sc].set_defaults(cmd = sc)
args = parser.parse_args(sys.argv[1:]) args = parser.parse_args(sys.argv[1:])