-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathranpass.py
executable file
·39 lines (34 loc) · 1.13 KB
/
ranpass.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import click
import pyperclip
from app import application
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click.group(context_settings=CONTEXT_SETTINGS)
def cli():
pass
@cli.command()
@click.option('-l', '--length', type=int, help='Length of password to be generated')
@click.option('-o', '--option', type=click.Choice(['1', '2', '3', '4']), default = '4',
help='''Options\n
1 - alphabetic lowercase\n
2 - alphabetic both cases\n
3 - alphanumeric\n
4 - alphanumeric + special characters'''
)
def generate(length, option):
"""generates a random password of length and type"""
logo = """
+-----------------------------+
| Thank you for using Ranpass |
+-----------------------------+
"""
# generate random password
password = application.generate(int(length), int(option))
# copy password to clipboard
try:
pyperclip.copy(password)
click.echo('Password has been copied to clipboard\n')
except Exception:
click.echo('Could not copy password to clipboad\n')
# output password and info to terminal
click.echo(password)
click.echo(logo)