| 1 |
#!/usr/bin/env python |
| 2 |
# -*- mode: Python; -*- |
| 3 |
|
| 4 |
import click |
| 5 |
import requests |
| 6 |
|
| 7 |
class config: |
| 8 |
SERVER='http://localhost:8080' |
| 9 |
|
| 10 |
@classmethod |
| 11 |
def path(cls, *args): |
| 12 |
return '/'.join([cls.SERVER] + list(args)) |
| 13 |
|
| 14 |
@click.group(invoke_without_command=True) |
| 15 |
@click.option('--server', default=config.SERVER) |
| 16 |
@click.pass_context |
| 17 |
def lager(ctx, server): |
| 18 |
config.SERVER=server |
| 19 |
if ctx.invoked_subcommand is None: |
| 20 |
ctx.invoke(status) |
| 21 |
|
| 22 |
@lager.command() |
| 23 |
def status(): |
| 24 |
r = requests.get(config.path('/api')) |
| 25 |
print(r.text) |
| 26 |
|
| 27 |
@lager.command() |
| 28 |
@click.argument('cursor') |
| 29 |
def step(cursor): |
| 30 |
r = requests.get(config.path('/api/step', cursor)) |
| 31 |
print(r.text) |
| 32 |
|
| 33 |
@lager.command() |
| 34 |
@click.argument('cursor') |
| 35 |
def goto(cursor): |
| 36 |
r = requests.post(config.path('/api/goto', cursor)) |
| 37 |
print(r.text) |
| 38 |
|
| 39 |
@lager.command() |
| 40 |
def undo(): |
| 41 |
r = requests.post(config.path('/api/undo')) |
| 42 |
print(r.text) |
| 43 |
|
| 44 |
@lager.command() |
| 45 |
def redo(): |
| 46 |
r = requests.post(config.path('/api/redo')) |
| 47 |
print(r.text) |
| 48 |
|
| 49 |
if __name__ == '__main__': |
| 50 |
lager() |