Add --quiet option, only output the generated passwords.

This commit is contained in:
Fredrik Soderblom 2020-05-03 10:49:46 +02:00
parent 6795454af1
commit 4596fc38ee

View File

@ -10,6 +10,10 @@ default_config_file=os.path.expanduser('~/.pwgen.cfg')
def main(): def main():
parser = argparse.ArgumentParser(description='Generate passwords') parser = argparse.ArgumentParser(description='Generate passwords')
parser.add_argument(
'--quiet', '-q',
action='store_true',
help='Only echo the generated passwords.')
parser.add_argument( parser.add_argument(
'--generate-config', '-g', '--generate-config', '-g',
action='store_true', action='store_true',
@ -82,6 +86,9 @@ def main():
args = vars(parser.parse_args()) args = vars(parser.parse_args())
quiet = args['quiet']
del args['quiet']
config_file = args['config_file'] config_file = args['config_file']
del args['config_file'] del args['config_file']
@ -103,6 +110,10 @@ def main():
pwds, seen_entropy = pwgen.generate_passwords(conf) pwds, seen_entropy = pwgen.generate_passwords(conf)
if (quiet):
for pw in pwds.keys():
print(pw)
else:
print("Generated {} passwords".format(len(pwds))) print("Generated {} passwords".format(len(pwds)))
if seen_entropy: if seen_entropy:
print("Full-knowledge entropy is {0:.2g}".format(seen_entropy)) print("Full-knowledge entropy is {0:.2g}".format(seen_entropy))