Skip to content
This repository was archived by the owner on Jan 23, 2026. It is now read-only.

Commit 6b80e39

Browse files
committed
Suppress newline from click.echo
1 parent 786e281 commit 6b80e39

9 files changed

Lines changed: 28 additions & 30 deletions

File tree

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from jumpstarter_cli_common import (
66
AliasedGroup,
77
OutputType,
8+
echo,
89
opt_context,
910
opt_kubeconfig,
1011
opt_labels,
@@ -38,7 +39,7 @@ def create(log_level: Optional[str]):
3839

3940
def print_created_client(client: V1Alpha1Client, output: OutputType):
4041
if output is not None:
41-
click.echo(client.dump(output))
42+
echo(client.dump(output))
4243

4344

4445
@create.command("client")
@@ -123,7 +124,7 @@ async def create_client(
123124

124125
def print_created_exporter(exporter: V1Alpha1Exporter, output: OutputType):
125126
if output is not None:
126-
click.echo(exporter.dump(output))
127+
echo(exporter.dump(output))
127128

128129

129130
@create.command("exporter")

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/create_test.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
credential:
6767
name: {name}-credential
6868
endpoint: {endpoint}
69-
7069
""".format(name=CLIENT_NAME, endpoint=CLIENT_ENDPOINT)
7170

7271
UNSAFE_CLIENT_CONFIG = ClientConfigV1Alpha1(
@@ -214,7 +213,6 @@ async def test_create_client(
214213
name: {name}-credential
215214
devices: []
216215
endpoint: {endpoint}
217-
218216
""".format(name=EXPORTER_NAME, endpoint=EXPORTER_ENDPOINT)
219217

220218
EXPORTER_CONFIG = ExporterConfigV1Alpha1(

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/get_test.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ def getheaders(self):
7575
credential:
7676
name: test-credential
7777
endpoint: grpc://example.com:443
78-
7978
"""
8079

8180

@@ -217,7 +216,6 @@ async def test_get_client(_load_kube_config_mock, get_client_mock: AsyncMock):
217216
name: another-credential
218217
endpoint: grpc://example.com:443
219218
kind: ClientList
220-
221219
"""
222220

223221
CLIENTS_LIST_NAME = """client.jumpstarter.dev/test
@@ -227,7 +225,6 @@ async def test_get_client(_load_kube_config_mock, get_client_mock: AsyncMock):
227225
CLIENTS_LIST_EMPTY_YAML = """apiVersion: jumpstarter.dev/v1alpha1
228226
items: []
229227
kind: ClientList
230-
231228
"""
232229

233230

@@ -334,7 +331,6 @@ async def test_get_clients(_load_kube_config_mock, list_clients_mock: AsyncMock)
334331
name: test-credential
335332
devices: []
336333
endpoint: grpc://example.com:443
337-
338334
"""
339335

340336

@@ -448,7 +444,6 @@ async def test_get_exporter(_load_kube_config_mock, get_exporter_mock: AsyncMock
448444
hardware: rpi4
449445
uuid: f7cd30ac-64a3-42c6-ba31-b25f033b97c1
450446
endpoint: grpc://example.com:443
451-
452447
"""
453448

454449

@@ -592,7 +587,6 @@ async def test_get_exporter_devices(_load_kube_config_mock, get_exporter_mock: A
592587
devices: []
593588
endpoint: grpc://example.com:443
594589
kind: ExporterList
595-
596590
"""
597591

598592
EXPORTERS_LIST_NAME = """exporter.jumpstarter.dev/test
@@ -760,7 +754,6 @@ async def test_get_exporters(_load_kube_config_mock, list_exporters_mock: AsyncM
760754
uuid: f7cd30ac-64a3-42c6-ba31-b25f033b97c1
761755
endpoint: grpc://example.com:443
762756
kind: ExporterList
763-
764757
"""
765758

766759
EXPORTERS_DEVICES_LIST_NAME = EXPORTERS_LIST_NAME
@@ -936,7 +929,6 @@ async def test_get_exporters_devices(_load_kube_config_mock, list_exporters_mock
936929
ended: true
937930
exporter:
938931
name: test_exporter
939-
940932
"""
941933

942934

@@ -1145,7 +1137,6 @@ async def test_get_lease(_load_kube_config_mock, get_lease_mock: AsyncMock):
11451137
exporter:
11461138
name: test_exporter
11471139
kind: LeaseList
1148-
11491140
"""
11501141

11511142
LEASES_LIST_NAME = """lease.jumpstarter.dev/82a8ac0d-d7ff-4009-8948-18a3c5c607b1

packages/jumpstarter-cli-admin/jumpstarter_cli_admin/print.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from jumpstarter_cli_common import (
33
OutputMode,
44
OutputType,
5+
echo,
56
make_table,
67
time_since,
78
)
@@ -26,19 +27,19 @@ def make_client_row(client: V1Alpha1Client):
2627
def print_client(client: V1Alpha1Client, output: OutputType):
2728
match output:
2829
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
29-
click.echo(client.dump(output))
30+
echo(client.dump(output))
3031
case _:
31-
click.echo(make_table(CLIENT_COLUMNS, [make_client_row(client)]))
32+
echo(make_table(CLIENT_COLUMNS, [make_client_row(client)]))
3233

3334

3435
def print_clients(clients: V1Alpha1List[V1Alpha1Client], namespace: str, output: OutputType):
3536
match output:
3637
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
37-
click.echo(clients.dump(output))
38+
echo(clients.dump(output))
3839
case _:
3940
if len(clients.items) == 0:
4041
raise click.ClickException(f'No resources found in "{namespace}" namespace')
41-
click.echo(make_table(CLIENT_COLUMNS, list(map(make_client_row, clients.items))))
42+
echo(make_table(CLIENT_COLUMNS, list(map(make_client_row, clients.items))))
4243

4344

4445
EXPORTER_COLUMNS = ["NAME", "ENDPOINT", "DEVICES", "AGE"]
@@ -80,26 +81,26 @@ def get_device_rows(exporters: list[V1Alpha1Exporter]):
8081
def print_exporter(exporter: V1Alpha1Exporter, devices: bool, output: OutputType):
8182
match output:
8283
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
83-
click.echo(exporter.dump(output))
84+
echo(exporter.dump(output))
8485
case _:
8586
if devices:
8687
# Print the devices for the exporter
87-
click.echo(make_table(DEVICE_COLUMNS, get_device_rows([exporter])))
88+
echo(make_table(DEVICE_COLUMNS, get_device_rows([exporter])))
8889
else:
89-
click.echo(make_table(EXPORTER_COLUMNS, [make_exporter_row(exporter)]))
90+
echo(make_table(EXPORTER_COLUMNS, [make_exporter_row(exporter)]))
9091

9192

9293
def print_exporters(exporters: V1Alpha1List[V1Alpha1Exporter], namespace: str, devices: bool, output: OutputType):
9394
match output:
9495
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
95-
click.echo(exporters.dump(output))
96+
echo(exporters.dump(output))
9697
case _:
9798
if len(exporters.items) == 0:
9899
raise click.ClickException(f'No resources found in "{namespace}" namespace')
99100
if devices:
100-
click.echo(make_table(DEVICE_COLUMNS, get_device_rows(exporters.items)))
101+
echo(make_table(DEVICE_COLUMNS, get_device_rows(exporters.items)))
101102
else:
102-
click.echo(make_table(EXPORTER_COLUMNS, list(map(make_exporter_row, exporters.items))))
103+
echo(make_table(EXPORTER_COLUMNS, list(map(make_exporter_row, exporters.items))))
103104

104105

105106
LEASE_COLUMNS = ["NAME", "CLIENT", "SELECTOR", "EXPORTER", "STATUS", "REASON", "BEGIN", "END", "DURATION", "AGE"]
@@ -144,16 +145,16 @@ def make_lease_row(lease: V1Alpha1Lease):
144145
def print_lease(lease: V1Alpha1Lease, output: OutputType):
145146
match output:
146147
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
147-
click.echo(lease.dump(output))
148+
echo(lease.dump(output))
148149
case _:
149-
click.echo(make_table(LEASE_COLUMNS, [make_lease_row(lease)]))
150+
echo(make_table(LEASE_COLUMNS, [make_lease_row(lease)]))
150151

151152

152153
def print_leases(leases: V1Alpha1List[V1Alpha1Lease], namespace: str, output: OutputType):
153154
match output:
154155
case OutputMode.JSON | OutputMode.YAML | OutputMode.NAME:
155-
click.echo(leases.dump(output))
156+
echo(leases.dump(output))
156157
case _:
157158
if len(leases.items) == 0:
158159
raise click.ClickException(f'No resources found in "{namespace}" namespace')
159-
click.echo(make_table(LEASE_COLUMNS, list(map(make_lease_row, leases.items))))
160+
echo(make_table(LEASE_COLUMNS, list(map(make_lease_row, leases.items))))

packages/jumpstarter-cli-common/jumpstarter_cli_common/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from .alias import AliasedGroup
22
from .config import opt_config
3+
from .echo import echo
34
from .opt import (
45
NameOutputType,
56
OutputMode,
@@ -21,6 +22,7 @@
2122

2223
__all__ = [
2324
"AliasedGroup",
25+
"echo",
2426
"make_table",
2527
"opt_config",
2628
"opt_context",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from functools import partial
2+
3+
import asyncclick as click
4+
5+
echo = partial(click.echo, nl=False)

packages/jumpstarter-kubernetes/jumpstarter_kubernetes/json.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ def dump(self, mode: OutputType = None):
1414
return super().dump(mode)
1515

1616
def dump_name(self):
17-
return "{}.jumpstarter.dev/{}".format(self.kind.lower(), self.metadata.name)
17+
return "{}.jumpstarter.dev/{}\n".format(self.kind.lower(), self.metadata.name)
1818

1919
model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True)

packages/jumpstarter-kubernetes/jumpstarter_kubernetes/list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ class V1Alpha1List(JsonBaseModel, Generic[T]):
1515
kind: Literal["List"] = Field(default="List")
1616

1717
def dump_name(self):
18-
return "\n".join(item.dump_name() for item in self.items)
18+
return "".join(item.dump_name() for item in self.items)

packages/jumpstarter/jumpstarter/common/pydantic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def dump(self, mode: OutputType = None):
2323
raise NotImplementedError("unimplemented output mode: {}".format(mode))
2424

2525
def dump_json(self):
26-
return self.model_dump_json(indent=4, by_alias=True)
26+
return self.model_dump_json(indent=4, by_alias=True) + "\n"
2727

2828
def dump_yaml(self):
2929
return yaml.safe_dump(self.model_dump(mode="json", by_alias=True), indent=2)

0 commit comments

Comments
 (0)