Skip to content

Commit

Permalink
Added list, connect, disconnect commands for ircb networks.
Browse files Browse the repository at this point in the history
  • Loading branch information
rtnpro committed Mar 23, 2016
1 parent 0269e77 commit bd7f9ae
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
45 changes: 45 additions & 0 deletions ircb/cli/network.py
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
import click

from tabulate import tabulate

from ircb.storeclient import NetworkStore
from ircb.lib.async import coroutinize

Expand Down Expand Up @@ -46,4 +48,47 @@ def create(user, network_name, host, port, nick, realname, username, password,
print(network.access_token)


@click.command(name='list')
@coroutinize
def ls(page=1):
networks = yield from NetworkStore.get({'query': {}})
headers = ['Id', 'User', 'Name', 'Nick', 'Server']
table = [
[network.id,
network.user_id,
network.name,
network.nickname,
'{}/{}'.format(network.hostname, network.port)]
for network in networks]
print(tabulate(table, headers, tablefmt='grid'))


@click.command(name='connect')
@click.argument('id')
@coroutinize
def connect(id):
network = yield from NetworkStore.update(
dict(
filter=('id', id),
update={
'status': '0'
})
)

@click.command(name='disconnect')
@click.argument('id')
@coroutinize
def disconnect(id):
network = yield from NetworkStore.update(
dict(
filter=('id', id),
update={
'status': '2'
})
)


network_cli.add_command(create)
network_cli.add_command(ls)
network_cli.add_command(connect)
network_cli.add_command(disconnect)
1 change: 1 addition & 0 deletions requirements.txt
Expand Up @@ -7,3 +7,4 @@ irc3==0.8.3
alembic==0.8.3
click==6.2
aioredis==0.2.4
tabulate==0.7.5

0 comments on commit bd7f9ae

Please sign in to comment.