I would like to build a cli-client for a daemon process. To build the cli I would like to use a cli library such as click or fire (others also possible). I thought I could use rpc to control the daemon functions but this does not seem to work.
I tried the following approach using click:
######## Daemon ########
from xmlrpc.server import SimpleXMLRPCServer
from xmlrpc.server import SimpleXMLRPCRequestHandler
import click
@click.group()
def cli():
pass
@cli.command()
@click.argument("a")
@click.argument("b")
def add(a,b):
return a + b
@cli.command()
@click.argument("a")
@click.argument("b")
def subtract(a,b):
return a - b
with SimpleXMLRPCServer(('localhost', 8000), requestHandler=RequestHandler) as server:
server.register_introspection_functions()
server.register_function(cli)
The client is
####### Client ########
import xmlrpc.client
port = 8000
proxy_address = "http://localhost:" + str(port) + "/"
with xmlrpc.client.ServerProxy(proxy_address) as proxy:
proxy.cli()
The error I get here is: AttributeError: 'Group' object has no attribute '__name__' on server.register_function(cli) in the daemon.
Assuming I could fix this I would run in to the problem that output of the cli function gets printed in the daemon process rather than the client.
I tried to find a cli client which handles this natively but all I could find was https://github.com/F483/apigen which hasn't been updated in 5 years.
Useful links:
- Click library: https://click.palletsprojects.com/en/8.0.x/
- Fire library: https://github.com/google/python-fire
- python xmlrpc : https://docs.python.org/3/library/xmlrpc.html