From bf6ce3fe9d890d8d69a0fdafde79c959c1f8d021 Mon Sep 17 00:00:00 2001 From: JansenBr Date: Fri, 29 Mar 2024 22:57:13 -0300 Subject: [PATCH] feat: adding a dedicated cli module --- morse_coder/cli.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 morse_coder/cli.py diff --git a/morse_coder/cli.py b/morse_coder/cli.py new file mode 100644 index 0000000..8e52f24 --- /dev/null +++ b/morse_coder/cli.py @@ -0,0 +1,39 @@ +import argparse + + +from morse import Morse +from sound import DitDash + + +def main(): + parser = argparse.ArgumentParser( + prog='morse_coder', + description='Simple CLI to encode text-to-morse and decode morse-to-text', + epilog='BYE | -... -.-- .' + ) + parser.add_argument( + 'action', choices=['translate'], + help='Translates the input text-to-morse or morse-to-text' + ) + parser.add_argument( + '--play', action='store_true', + help='Play the message in Morse code' + ) + parser.add_argument( + 'text', nargs='+', + help='String text to be translated' + ) + args = parser.parse_args() + + morse = Morse() + out = morse.translate(args.text[0]) + print(out) + + if morse._is_morse(out) and args.play: + sound = DitDash() + sound.play_message(out) + + +if __name__=='__main__': + main() + \ No newline at end of file