mirror of
https://github.com/rjNemo/pass-gen
synced 2026-06-06 02:26:42 +00:00
66 lines
1.7 KiB
Python
66 lines
1.7 KiB
Python
import random as r
|
|
from typing import Optional
|
|
|
|
import typer
|
|
|
|
import app.repositories.sqlite as sqlite
|
|
import app.usecases.pass_gen as pass_gen
|
|
import app.usecases.utils as utils
|
|
|
|
app = typer.Typer()
|
|
|
|
|
|
@app.command()
|
|
def save(
|
|
length: int = typer.Option(
|
|
8,
|
|
"--length",
|
|
"-l",
|
|
help="Length of the generated password.",
|
|
),
|
|
numbers: bool = typer.Option(
|
|
True,
|
|
"--numbers",
|
|
"-n",
|
|
help="If the generated password should include numeric characters.",
|
|
),
|
|
symbols: bool = typer.Option(
|
|
False,
|
|
"--symbols",
|
|
"-s",
|
|
help="If the generated password should include special characters.",
|
|
),
|
|
file: Optional[str] = typer.Option(
|
|
None,
|
|
"--file",
|
|
"-f",
|
|
help="Path to the file where the generated password should be saved.",
|
|
),
|
|
random: bool = True,
|
|
) -> None:
|
|
sqlite_repo = sqlite.get_instance()
|
|
seed = r.randint(0, 100) if random else 0
|
|
options = pass_gen.PassGenOptions(
|
|
seed=seed,
|
|
length=length,
|
|
symbols=symbols,
|
|
numbers=numbers,
|
|
)
|
|
|
|
password = pass_gen.generate_password(sqlite_repo, options)
|
|
|
|
typer.echo(typer.style(f"🔐 {password}", fg=typer.colors.GREEN, bold=True))
|
|
|
|
if file is not None:
|
|
utils.save_to_file(file, password)
|
|
return typer.echo(f"The password has been saved to: {file} 🗄")
|
|
|
|
utils.copy_to_clipboard(password)
|
|
return typer.echo("The password has been copied to your clipboard 😉\nPaste it using cmd + v")
|
|
|
|
|
|
@app.command()
|
|
def read() -> None:
|
|
sqlite_repo = sqlite.get_instance()
|
|
stored_passwords = sqlite_repo.list_all()
|
|
typer.echo(stored_passwords)
|