Skip to content

Commit

Permalink
feat: adding a dedicated cli module
Browse files Browse the repository at this point in the history
  • Loading branch information
JansenBr committed Mar 30, 2024
1 parent 6cc7682 commit bf6ce3f
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions morse_coder/cli.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit bf6ce3f

Please sign in to comment.