Use argparse
This commit is contained in:
parent
79f433167c
commit
e238d433ee
|
@ -24,5 +24,5 @@ Find the line of broker output giving the root capability:
|
||||||
Then, run [chat.py](chat.py) several times in several separate windows:
|
Then, run [chat.py](chat.py) several times in several separate windows:
|
||||||
|
|
||||||
python chat.py \
|
python chat.py \
|
||||||
'<tcp "localhost" 8001>' \
|
--address '<tcp "localhost" 8001>' \
|
||||||
'<ref "syndicate" [] #x"a6480df5306611ddd0d3882b546e1977">'
|
--cap '<ref "syndicate" [] #x"a6480df5306611ddd0d3882b546e1977">'
|
||||||
|
|
17
chat.py
17
chat.py
|
@ -1,22 +1,29 @@
|
||||||
import sys
|
import sys
|
||||||
|
import argparse
|
||||||
import asyncio
|
import asyncio
|
||||||
import random
|
import random
|
||||||
import syndicate
|
import syndicate
|
||||||
from syndicate import patterns as P, actor, dataspace
|
from syndicate import patterns as P, actor, dataspace
|
||||||
from syndicate.schema import simpleChatProtocol, sturdy
|
from syndicate.schema import simpleChatProtocol, sturdy
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description='Simple dataspace-server-mediated text chat.',
|
||||||
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
|
||||||
|
parser.add_argument('--address', metavar='\'<tcp "HOST" PORT>\'',
|
||||||
|
help='transport address of the server',
|
||||||
|
default='<ws "ws://localhost:8001/">')
|
||||||
|
parser.add_argument('--cap', metavar='\'<ref ...>\'',
|
||||||
|
help='capability for the dataspace on the server',
|
||||||
|
default='<ref "syndicate" [] #[pkgN9TBmEd3Q04grVG4Zdw==]>')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
Present = simpleChatProtocol.Present
|
Present = simpleChatProtocol.Present
|
||||||
Says = simpleChatProtocol.Says
|
Says = simpleChatProtocol.Says
|
||||||
|
|
||||||
conn_str = '<ws "ws://localhost:8001/">'
|
|
||||||
cap_str = '<ref "syndicate" [] #[pkgN9TBmEd3Q04grVG4Zdw==]>'
|
|
||||||
cap = sturdy.SturdyRef.decode(syndicate.parse(cap_str))
|
|
||||||
|
|
||||||
@actor.run_system(name = 'chat', debug = False)
|
@actor.run_system(name = 'chat', debug = False)
|
||||||
def main(turn):
|
def main(turn):
|
||||||
root_facet = turn._facet
|
root_facet = turn._facet
|
||||||
|
|
||||||
@syndicate.relay.connect(turn, conn_str, cap)
|
@syndicate.relay.connect(turn, args.address, sturdy.SturdyRef.decode(syndicate.parse(args.cap)))
|
||||||
def on_connected(turn, ds):
|
def on_connected(turn, ds):
|
||||||
me = 'user_' + str(random.randint(10, 1000))
|
me = 'user_' + str(random.randint(10, 1000))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue