Skip to content

Commit

Permalink
fixed CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddhesh-Agarwal committed May 15, 2024
1 parent b42b51f commit c6dfec0
Showing 1 changed file with 20 additions and 11 deletions.
31 changes: 20 additions & 11 deletions cryptmoji/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from typing import Annotated
from rich.console import Console
from typer import Typer, prompt, Option
from typer import Typer, prompt

from cryptmoji.main import decrypt, encrypt
from cryptmoji.version import __version__
Expand All @@ -12,24 +11,34 @@
@app.command("encrypt")
def cli_encrypt(text: str):
"""Encrypts a string as a string of emojis."""
key = prompt("Enter key", default=None)
console.print(encrypt(text, key=key))
key = prompt("Enter key (optional)", default="", show_default=False)
key = key if key else None
print(f"{key=}")
console.print(f"The encrypted string is: {encrypt(text, key=key)}")


@app.command("decrypt")
def cli_decrypt(text: str):
"""Decrypts a string of emojis."""
key = prompt("Enter key", default=None)
console.print(decrypt(text, key=key))
key = prompt("Enter key (optional)", default="", show_default=False)
key = key if key else None
print(f"{key=}")
console.print(f"The decrypted string is: {decrypt(text, key=key)}")


def cli_version(
show_version: Annotated[bool, Option("--version", "-v", is_eager=True)]
):
@app.command("version")
def cli_version():
"""Prints the version of the library."""
version = ".".join(str(i) for i in __version__)
if show_version:
console.print(f"cryptmoji v{version}")
console.print(f"cryptmoji [bold green]v{version}[/]")


@app.command("docs")
def cli_docs():
"""Launches the documentation in the browser."""
import webbrowser

webbrowser.open("https://github.com/Siddhesh-Agarwal/cryptmoji/wiki")


if __name__ == "__main__":
Expand Down

0 comments on commit c6dfec0

Please sign in to comment.