Skip to content

Commit 42246f6

Browse files
committed
cli: reworked CLI decorator names
1 parent 97ac67b commit 42246f6

File tree

11 files changed

+122
-95
lines changed

11 files changed

+122
-95
lines changed

examples/metricq_client.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import aiomonitor # type: ignore
4545

4646
import metricq
47-
from metricq.cli import metricq_command
4847

4948
logger = metricq.get_logger()
5049

@@ -59,7 +58,7 @@ async def run(server: str, token: str) -> None:
5958
await client.stopped()
6059

6160

62-
@metricq_command(default_token="client-py-example")
61+
@metricq.cli.command(default_token="client-py-example")
6362
def main(server: str, token: str) -> None:
6463
asyncio.run(run(server, token))
6564

examples/metricq_get_history.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,8 @@
3434
import click
3535

3636
import metricq
37-
from metricq.cli import metricq_command
38-
from metricq.cli.decorator import metricq_metric_option
39-
from metricq.logging import get_logger
4037

41-
logger = get_logger()
38+
logger = metricq.get_logger()
4239

4340

4441
async def aget_history(
@@ -91,8 +88,8 @@ async def aget_history(
9188
click.echo(aggregate)
9289

9390

94-
@metricq_command(default_token="history-py-dummy")
95-
@metricq_metric_option()
91+
@metricq.cli.command(default_token="history-py-dummy")
92+
@metricq.cli.metric_option()
9693
@click.option("--list-metrics", is_flag=True)
9794
@click.option("--list-metadata", is_flag=True)
9895
def get_history(

examples/metricq_get_history_raw.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import click
3434

3535
import metricq
36-
from metricq.cli import metricq_command
37-
from metricq.cli.decorator import metricq_metric_option
3836
from metricq.history_client import HistoryRequestType
3937

4038

@@ -73,8 +71,8 @@ async def aget_history(server: str, token: str, metric: str) -> None:
7371
await client.stop(None)
7472

7573

76-
@metricq_command(default_token="history-py-dummy")
77-
@metricq_metric_option()
74+
@metricq.cli.command(default_token="history-py-dummy")
75+
@metricq.cli.metric_option()
7876
def get_history(server: str, token: str, metric: str) -> None:
7977
asyncio.run(aget_history(server, token, metric))
8078

examples/metricq_pandas.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import click
3434

3535
import metricq
36-
from metricq.cli import metricq_command
37-
from metricq.cli.decorator import metricq_metric_option
3836
from metricq.pandas import PandasHistoryClient
3937

4038
logger = metricq.get_logger()
@@ -73,8 +71,8 @@ async def aget_history(server: str, token: str, metric: str) -> None:
7371
click.echo("----------")
7472

7573

76-
@metricq_command(default_token="history-py-dummy")
77-
@metricq_metric_option(default="example.quantity")
74+
@metricq.cli.command(default_token="history-py-dummy")
75+
@metricq.cli.metric_option(default="example.quantity")
7876
def get_history(server: str, token: str, metric: str) -> None:
7977
asyncio.run(aget_history(server, token, metric))
8078

examples/metricq_sink.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@
3333

3434
import metricq
3535
from metricq import Metric
36-
from metricq.cli import metricq_command
37-
from metricq.cli.decorator import metricq_metric_option
38-
from metricq.logging import get_logger
3936

40-
logger = get_logger()
37+
logger = metricq.get_logger()
4138

4239

4340
# To implement a MetricQ Sink, subclass metricq.Sink
@@ -70,8 +67,8 @@ async def on_data(
7067
)
7168

7269

73-
@metricq_command(default_token="sink-py-dummy")
74-
@metricq_metric_option(multiple=True)
70+
@metricq.cli.command(default_token="sink-py-dummy")
71+
@metricq.cli.metric_option(multiple=True)
7572
def source(server: str, token: str, metric: list[Metric]) -> None:
7673
# Initialize the DummySink class with a list of metrics given on the
7774
# command line.

examples/metricq_source.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@
3131
from typing import Any
3232

3333
import metricq
34-
from metricq.cli import metricq_command
35-
from metricq.logging import get_logger
3634

37-
logger = get_logger()
35+
logger = metricq.get_logger()
3836

3937

4038
class DummySource(metricq.IntervalSource):
@@ -65,7 +63,7 @@ async def update(self) -> None:
6563
)
6664

6765

68-
@metricq_command(default_token="source-py-dummy")
66+
@metricq.cli.command(default_token="source-py-dummy")
6967
def source(server: str, token: str) -> None:
7068
src = DummySource(token=token, url=server)
7169
src.run()

examples/metricq_synchronous_source.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@
3333
import random
3434
import time
3535

36+
import metricq
3637
from metricq import SynchronousSource, Timestamp
37-
from metricq.cli import metricq_command
38-
from metricq.logging import get_logger
3938

40-
logger = get_logger()
39+
logger = metricq.get_logger()
4140

4241

43-
@metricq_command(default_token="source-py-dummy")
42+
@metricq.cli.command(default_token="source-py-dummy")
4443
def synchronous_source(server: str, token: str) -> None:
4544
ssource = SynchronousSource(token=token, url=server)
4645
ssource.declare_metrics(

metricq/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@
5252
)
5353
from .version import __version__
5454

55+
try:
56+
from . import cli
57+
except ImportError:
58+
pass
59+
5560
# Please keep sorted alphabetically to avoid merge conflicts
5661
__all__ = [
5762
"Agent",
@@ -76,4 +81,5 @@
7681
"Timestamp",
7782
"TimeValue",
7883
"__version__",
84+
"cli",
7985
]

metricq/cli/__init__.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from .decorator import (
2-
metricq_command,
3-
metricq_metric_option,
4-
metricq_server_option,
5-
metricq_syslog_option,
6-
metricq_token_option,
2+
command,
3+
metric_option,
4+
server_option,
5+
syslog_option,
6+
token_option,
77
)
88
from .params import (
99
ChoiceParam,
@@ -21,9 +21,9 @@
2121
"TemplateStringParam",
2222
"TimestampParam",
2323
"MetricParam",
24-
"metricq_command",
25-
"metricq_metric_option",
26-
"metricq_server_option",
27-
"metricq_syslog_option",
28-
"metricq_token_option",
24+
"command",
25+
"metric_option",
26+
"server_option",
27+
"syslog_option",
28+
"token_option",
2929
]

0 commit comments

Comments
 (0)