#!/usr/bin/env python3
# This file is placed in the Public Domain.
# pylint: disable=C0413,W0611


"cli"


import getpass
import sys


from rssbot.command import Commands
from rssbot.config  import Config
from rssbot.errors  import Errors, errors
from rssbot.main    import cmnd, enable, init, wrap
from rssbot.modules import face
from rssbot.parse   import parse


Cfg = Config()
TXT = """[Unit]
Description=24/7 Feed Fetcher
After=network-online.target

[Service]
Type=simple
User=%s
Group=%s
ExecStart=/home/%s/.local/bin/rssbots

[Install]
WantedBy=multi-user.target"""

def srv(event):
    "create service file (pipx)."
    if event.args:
        name = event.args[0]
    else:
        name  = getpass.getuser()
    event.reply(TXT % (name, name, name))


Commands.add(srv)


def main():
    "main"
    parse(Cfg, " ".join(sys.argv[1:]))
    if "v" in Cfg.opts:
        enable(print)
    if "h" in Cfg.opts:
        cmnd("hlp", print)
    elif Cfg.txt:
        cmnd(Cfg.otxt, print)


if __name__ == "__main__":
    Errors.out = print
    wrap(main)
    errors()
