22import json
33import argparse
44from datetime import timedelta , datetime , timezone
5- from pprint import pprint
65
76import click
87
@@ -55,28 +54,28 @@ def main(ctx, testing: bool, host: str, port: int):
5554@click .argument ("bucket_id" )
5655@click .argument ("data" )
5756@click .option ("--pulsetime" , default = 60 , help = "pulsetime to use for merging heartbeats" )
58- @click .pass_context
59- def heartbeat (ctx , bucket_id : str , data : str , pulsetime : int ):
57+ @click .pass_obj
58+ def heartbeat (obj : _Context , bucket_id : str , data : str , pulsetime : int ):
6059 now = datetime .now (timezone .utc )
6160 e = Event (duration = 0 , data = json .loads (data ), timestamp = now )
6261 print (e )
63- ctx . obj .client .heartbeat (bucket_id , e , pulsetime )
62+ obj .client .heartbeat (bucket_id , e , pulsetime )
6463
6564
6665@main .command (help = "List all buckets" )
67- @click .pass_context
68- def buckets (ctx ):
69- buckets = ctx . obj .client .get_buckets ()
66+ @click .pass_obj
67+ def buckets (obj : _Context ):
68+ buckets = obj .client .get_buckets ()
7069 print ("Buckets:" )
7170 for bucket in buckets :
7271 print (" - {}" .format (bucket ))
7372
7473
7574@main .command (help = "Query events from bucket with ID `bucket_id`" )
7675@click .argument ("bucket_id" )
77- @click .pass_context
78- def events (ctx , bucket_id : str ):
79- events = ctx . obj .client .get_events (bucket_id )
76+ @click .pass_obj
77+ def events (obj : _Context , bucket_id : str ):
78+ events = obj .client .get_events (bucket_id )
8079 print ("events:" )
8180 for e in events :
8281 print (
@@ -95,9 +94,9 @@ def events(ctx, bucket_id: str):
9594@click .option ("--json" , is_flag = True )
9695@click .option ("--start" , default = now - td1day , type = click .DateTime ())
9796@click .option ("--stop" , default = now + td1yr , type = click .DateTime ())
98- @click .pass_context
97+ @click .pass_obj
9998def query (
100- ctx ,
99+ obj : _Context ,
101100 path : str ,
102101 cache : bool ,
103102 _json : bool ,
@@ -107,7 +106,7 @@ def query(
107106):
108107 with open (path ) as f :
109108 query = f .read ()
110- result = ctx . obj .client .query (query , [(start , stop )], cache = cache , name = name )
109+ result = obj .client .query (query , [(start , stop )], cache = cache , name = name )
111110 if _json :
112111 print (json .dumps (result ))
113112 else :
0 commit comments