36 lines
676 B
Python
36 lines
676 B
Python
import os
|
|
import sys
|
|
import click
|
|
import json
|
|
|
|
from .config import FIFO_PATH
|
|
|
|
|
|
def send_message(message: str) -> None:
|
|
fifo_name = FIFO_PATH
|
|
|
|
if not os.path.exists(fifo_name):
|
|
sys.exit(1)
|
|
|
|
# Starting two readers and one writer, but only one reader
|
|
# will be reading at the same time.
|
|
content = {'type': 'message', 'content': message}
|
|
with open(fifo_name, 'w') as file:
|
|
file.write(json.dumps(content))
|
|
file.write('\0')
|
|
|
|
|
|
@click.group()
|
|
def cli() -> None:
|
|
pass
|
|
|
|
|
|
@cli.command()
|
|
@click.argument('message', nargs=-1)
|
|
def message(message: list) -> None:
|
|
send_message(' '.join(message))
|
|
|
|
|
|
if __name__ == '__main__':
|
|
cli()
|