mirror of
https://github.com/rjNemo/pass-gen
synced 2026-06-06 02:26:42 +00:00
feat: save to file
This commit is contained in:
parent
89beba48cc
commit
2277ba85ad
5 changed files with 22 additions and 3 deletions
|
|
@ -6,5 +6,5 @@
|
|||
- [x] Minimal length
|
||||
- [x] Include symbols
|
||||
- [x] Include numbers
|
||||
- [ ] As a user I want the generated password to be copied to the clipboard
|
||||
- [x] As a user I want the generated password to be copied to the clipboard
|
||||
- [x] As a user I want the generated password to be saved to a file
|
||||
|
|
|
|||
13
app/main.py
13
app/main.py
|
|
@ -1,5 +1,6 @@
|
|||
import random as r
|
||||
import subprocess
|
||||
from typing import Optional
|
||||
|
||||
import typer
|
||||
|
||||
|
|
@ -18,13 +19,21 @@ def main(
|
|||
symbols: bool = typer.Option(
|
||||
False, help="If the generated password should include special characters."
|
||||
),
|
||||
file: Optional[str] = typer.Option(
|
||||
None, help="Path to the file where the generated password should be saved."
|
||||
),
|
||||
) -> None:
|
||||
seed = r.randint(0, 100) if random else 0
|
||||
password = generate_password(seed, length, symbols, numbers)
|
||||
|
||||
subprocess.run("pbcopy", universal_newlines=True, input=password)
|
||||
|
||||
typer.echo(typer.style(f"🔐 {password}", fg=typer.colors.GREEN, bold=True))
|
||||
|
||||
if file is not None:
|
||||
with open(file, "w") as f:
|
||||
f.write(password)
|
||||
return
|
||||
|
||||
subprocess.run("pbcopy", universal_newlines=True, input=password)
|
||||
typer.echo(
|
||||
"The password has been copied to your clipboard 😉\nPaste it using cmd + v"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,14 @@ def test_cli_can_set_numbers() -> None:
|
|||
assert "yWAcqGFz" in result.stdout
|
||||
|
||||
|
||||
def test_cli_can_save_to_file() -> None:
|
||||
args = ["--file", "test.txt"]
|
||||
_ = _run_cli(*args)
|
||||
with open("test.txt", "r") as f:
|
||||
content = f.read()
|
||||
assert "2yW4AcqG" in content
|
||||
|
||||
|
||||
def _run_cli(*args) -> Result:
|
||||
result = runner.invoke(app, ["--no-random", *args])
|
||||
assert result.exit_code == 0
|
||||
|
|
|
|||
1
psswd.txt
Normal file
1
psswd.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
-'R>;X*cut&2^aOK
|
||||
1
test.txt
Normal file
1
test.txt
Normal file
|
|
@ -0,0 +1 @@
|
|||
2yW4AcqG
|
||||
Loading…
Reference in a new issue