teqconnect-cli 0.0.1__tar.gz → 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- teqconnect_cli-0.1.1/.gitignore +19 -0
- teqconnect_cli-0.1.1/PKG-INFO +139 -0
- teqconnect_cli-0.1.1/README.md +114 -0
- teqconnect_cli-0.1.1/pyproject.toml +50 -0
- teqconnect_cli-0.1.1/teqconnect_cli/__init__.py +10 -0
- teqconnect_cli-0.1.1/teqconnect_cli/_output.py +116 -0
- teqconnect_cli-0.1.1/teqconnect_cli/_version.py +1 -0
- teqconnect_cli-0.1.1/teqconnect_cli/main.py +787 -0
- teqconnect_cli-0.1.1/teqconnect_cli/vpn_host.py +856 -0
- teqconnect_cli-0.0.1/.gitignore +0 -3
- teqconnect_cli-0.0.1/LICENSE +0 -202
- teqconnect_cli-0.0.1/PKG-INFO +0 -17
- teqconnect_cli-0.0.1/README.md +0 -5
- teqconnect_cli-0.0.1/pyproject.toml +0 -20
- teqconnect_cli-0.0.1/src/teqconnect_cli/__init__.py +0 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
scripts/release/release.env
|
|
2
|
+
scripts/release/local/
|
|
3
|
+
scripts/release/history.jsonl
|
|
4
|
+
examples/*/.env
|
|
5
|
+
.DS_Store
|
|
6
|
+
__pycache__/
|
|
7
|
+
*.py[cod]
|
|
8
|
+
*.egg-info/
|
|
9
|
+
.venv/
|
|
10
|
+
dist/
|
|
11
|
+
build/
|
|
12
|
+
node_modules/
|
|
13
|
+
*.tsbuildinfo
|
|
14
|
+
.coverage
|
|
15
|
+
.pytest_cache/
|
|
16
|
+
.ruff_cache/
|
|
17
|
+
.mypy_cache/
|
|
18
|
+
*.tgz
|
|
19
|
+
.turbo/
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: teqconnect-cli
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: The teq command-line interface for TeqConnect. Login, IoT, AI, webhooks, and VPN enrollment.
|
|
5
|
+
Author: IO-TEQ
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Keywords: cli,iot,teqconnect,vpn,webhooks
|
|
8
|
+
Classifier: Development Status :: 4 - Beta
|
|
9
|
+
Classifier: Environment :: Console
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
12
|
+
Classifier: Operating System :: OS Independent
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Requires-Dist: cryptography>=50.0.2
|
|
19
|
+
Requires-Dist: jmespath>=1.1.0
|
|
20
|
+
Requires-Dist: pyyaml>=6.0.3
|
|
21
|
+
Requires-Dist: rich>=15.0.0
|
|
22
|
+
Requires-Dist: teqconnect<0.2,>=0.1
|
|
23
|
+
Requires-Dist: typer>=0.29.2
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# teqconnect-cli
|
|
27
|
+
|
|
28
|
+
`teq` is the command-line interface for TeqConnect. Every command calls the [Python SDK](https://pypi.org/project/teqconnect/). The CLI does not open its own HTTP or WebSocket connection.
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
pip install teqconnect-cli
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Python 3.11 or newer. `uv tool install teqconnect-cli` and `pipx install teqconnect-cli` both work when the system Python is 3.11 or newer.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
teq --version
|
|
38
|
+
teq --help
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Sign in
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
teq configure --endpoint https://test.tccloud.io
|
|
45
|
+
teq login
|
|
46
|
+
teq whoami
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
| Environment | Origin |
|
|
50
|
+
| --- | --- |
|
|
51
|
+
| Test | `https://test.tccloud.io` |
|
|
52
|
+
| Staging | `https://staging.tccloud.io` |
|
|
53
|
+
| Production | `https://tccloud.io` |
|
|
54
|
+
|
|
55
|
+
`teq login` prints a device code and a verification URL. The resulting credential is stored in the `default` profile. `TEQCONNECT_ENDPOINT` and `--endpoint` win over the saved profile. `TEQCONNECT_ENV=test` selects the test origin when nothing else is set.
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
teq logout
|
|
59
|
+
teq token
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Everyday commands
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
teq iam actions list
|
|
66
|
+
teq ai models list
|
|
67
|
+
teq ai complete '[{"role":"user","content":"Hello"}]' --max-tokens 256
|
|
68
|
+
teq iot devices list
|
|
69
|
+
teq iot devices get DEVICE_ID
|
|
70
|
+
teq webhooks list
|
|
71
|
+
teq vpn status
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Output is JSON. Change it per invocation:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
teq iot devices list --output table
|
|
78
|
+
teq whoami --output yaml
|
|
79
|
+
teq iot devices list --query 'data[0].id'
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`--output` accepts `json`, `table`, `yaml`, or `text`. `--query` is JMESPath over the unwrapped `data`. `--debug` prints which credential source was used: `argument`, `env`, `credentials_file`, `sso_cache`, or `session_token`. `--profile` selects a named profile. `--org` is accepted and does not switch the organization inside the token.
|
|
83
|
+
|
|
84
|
+
Exit `0` is success, `1` is an API error, `2` is bad usage, and `3` means the credential or endpoint is missing.
|
|
85
|
+
|
|
86
|
+
## Command groups
|
|
87
|
+
|
|
88
|
+
| Group | Examples |
|
|
89
|
+
| --- | --- |
|
|
90
|
+
| session | `configure`, `login`, `logout`, `whoami`, `token` |
|
|
91
|
+
| `teq iam` | `actions list` |
|
|
92
|
+
| `teq ai` | `complete`, `models list`, `models catalog`, `usage get`, `invocations list` |
|
|
93
|
+
| `teq iot` | `devices list`, `devices get`, `devices command`, `registries list`, `watch` |
|
|
94
|
+
| `teq webhooks` | `list`, `create`, `test`, `rotate-secret`, `deliveries` |
|
|
95
|
+
| `teq vpn` | `enroll`, `status`, `up`, `down`, `renew`, `leave` |
|
|
96
|
+
| raw | `teq api GET /api/v1/sts/whoami` |
|
|
97
|
+
|
|
98
|
+
`teq iot watch` follows live device events through the SDK realtime client. That path needs the realtime extra: `pip install 'teqconnect[realtime]'`.
|
|
99
|
+
|
|
100
|
+
## VPN on a host
|
|
101
|
+
|
|
102
|
+
`teq vpn enroll` registers this machine, writes the strongSwan config, and starts the tunnel.
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
sudo teq vpn enroll --org ORG_ID --pool POOL_ID --auth cert
|
|
106
|
+
teq vpn status
|
|
107
|
+
sudo teq vpn down # tunnel only; the enrollment stays
|
|
108
|
+
sudo teq vpn up
|
|
109
|
+
sudo teq vpn leave # unenroll; packages stay installed
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
`--org` is required. It salts the host fingerprint. `--auth` is `cert` or `psk`. `--full-tunnel` asks for a full tunnel. The default is split.
|
|
113
|
+
|
|
114
|
+
A host whose system Python is older than 3.11, including Ubuntu 22.04, should install `teq` with the managed interpreter under `/opt/teqconnect-cli` rather than with the distro Python. `sudo teq vpn` then uses that binary at `/usr/local/bin/teq`.
|
|
115
|
+
|
|
116
|
+
`teq vpn doctor` reports whether the local tunnel setup is consistent. `teq vpn renew` and `teq vpn rotate` refresh the enrollment when the server says the material is due.
|
|
117
|
+
|
|
118
|
+
## Credentials in scripts
|
|
119
|
+
|
|
120
|
+
The CLI and the SDK share a credential chain.
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
export TEQCONNECT_ENDPOINT=https://test.tccloud.io
|
|
124
|
+
export TEQCONNECT_ACCESS_KEY_ID=...
|
|
125
|
+
export TEQCONNECT_SECRET_ACCESS_KEY=...
|
|
126
|
+
teq whoami
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
`TEQCONNECT_SESSION_TOKEN` and `TEQCONNECT_CREDENTIALS` (JSON with `access_key_id` and `secret_access_key`) are the other env sources. A profile from `teq login` is the fallback.
|
|
130
|
+
|
|
131
|
+
## Related
|
|
132
|
+
|
|
133
|
+
| Package | Use it for |
|
|
134
|
+
| --- | --- |
|
|
135
|
+
| [`teqconnect`](https://pypi.org/project/teqconnect/) | The Python SDK this CLI calls |
|
|
136
|
+
| [`@teqconnect/sdk`](https://www.npmjs.com/package/@teqconnect/sdk) | The same API from Node.js |
|
|
137
|
+
| [`@teqconnect/express`](https://www.npmjs.com/package/@teqconnect/express) | Sign in with TeqConnect on Express |
|
|
138
|
+
|
|
139
|
+
Apache-2.0.
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# teqconnect-cli
|
|
2
|
+
|
|
3
|
+
`teq` is the command-line interface for TeqConnect. Every command calls the [Python SDK](https://pypi.org/project/teqconnect/). The CLI does not open its own HTTP or WebSocket connection.
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
pip install teqconnect-cli
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Python 3.11 or newer. `uv tool install teqconnect-cli` and `pipx install teqconnect-cli` both work when the system Python is 3.11 or newer.
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
teq --version
|
|
13
|
+
teq --help
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Sign in
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
teq configure --endpoint https://test.tccloud.io
|
|
20
|
+
teq login
|
|
21
|
+
teq whoami
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
| Environment | Origin |
|
|
25
|
+
| --- | --- |
|
|
26
|
+
| Test | `https://test.tccloud.io` |
|
|
27
|
+
| Staging | `https://staging.tccloud.io` |
|
|
28
|
+
| Production | `https://tccloud.io` |
|
|
29
|
+
|
|
30
|
+
`teq login` prints a device code and a verification URL. The resulting credential is stored in the `default` profile. `TEQCONNECT_ENDPOINT` and `--endpoint` win over the saved profile. `TEQCONNECT_ENV=test` selects the test origin when nothing else is set.
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
teq logout
|
|
34
|
+
teq token
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Everyday commands
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
teq iam actions list
|
|
41
|
+
teq ai models list
|
|
42
|
+
teq ai complete '[{"role":"user","content":"Hello"}]' --max-tokens 256
|
|
43
|
+
teq iot devices list
|
|
44
|
+
teq iot devices get DEVICE_ID
|
|
45
|
+
teq webhooks list
|
|
46
|
+
teq vpn status
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Output is JSON. Change it per invocation:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
teq iot devices list --output table
|
|
53
|
+
teq whoami --output yaml
|
|
54
|
+
teq iot devices list --query 'data[0].id'
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
`--output` accepts `json`, `table`, `yaml`, or `text`. `--query` is JMESPath over the unwrapped `data`. `--debug` prints which credential source was used: `argument`, `env`, `credentials_file`, `sso_cache`, or `session_token`. `--profile` selects a named profile. `--org` is accepted and does not switch the organization inside the token.
|
|
58
|
+
|
|
59
|
+
Exit `0` is success, `1` is an API error, `2` is bad usage, and `3` means the credential or endpoint is missing.
|
|
60
|
+
|
|
61
|
+
## Command groups
|
|
62
|
+
|
|
63
|
+
| Group | Examples |
|
|
64
|
+
| --- | --- |
|
|
65
|
+
| session | `configure`, `login`, `logout`, `whoami`, `token` |
|
|
66
|
+
| `teq iam` | `actions list` |
|
|
67
|
+
| `teq ai` | `complete`, `models list`, `models catalog`, `usage get`, `invocations list` |
|
|
68
|
+
| `teq iot` | `devices list`, `devices get`, `devices command`, `registries list`, `watch` |
|
|
69
|
+
| `teq webhooks` | `list`, `create`, `test`, `rotate-secret`, `deliveries` |
|
|
70
|
+
| `teq vpn` | `enroll`, `status`, `up`, `down`, `renew`, `leave` |
|
|
71
|
+
| raw | `teq api GET /api/v1/sts/whoami` |
|
|
72
|
+
|
|
73
|
+
`teq iot watch` follows live device events through the SDK realtime client. That path needs the realtime extra: `pip install 'teqconnect[realtime]'`.
|
|
74
|
+
|
|
75
|
+
## VPN on a host
|
|
76
|
+
|
|
77
|
+
`teq vpn enroll` registers this machine, writes the strongSwan config, and starts the tunnel.
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
sudo teq vpn enroll --org ORG_ID --pool POOL_ID --auth cert
|
|
81
|
+
teq vpn status
|
|
82
|
+
sudo teq vpn down # tunnel only; the enrollment stays
|
|
83
|
+
sudo teq vpn up
|
|
84
|
+
sudo teq vpn leave # unenroll; packages stay installed
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
`--org` is required. It salts the host fingerprint. `--auth` is `cert` or `psk`. `--full-tunnel` asks for a full tunnel. The default is split.
|
|
88
|
+
|
|
89
|
+
A host whose system Python is older than 3.11, including Ubuntu 22.04, should install `teq` with the managed interpreter under `/opt/teqconnect-cli` rather than with the distro Python. `sudo teq vpn` then uses that binary at `/usr/local/bin/teq`.
|
|
90
|
+
|
|
91
|
+
`teq vpn doctor` reports whether the local tunnel setup is consistent. `teq vpn renew` and `teq vpn rotate` refresh the enrollment when the server says the material is due.
|
|
92
|
+
|
|
93
|
+
## Credentials in scripts
|
|
94
|
+
|
|
95
|
+
The CLI and the SDK share a credential chain.
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
export TEQCONNECT_ENDPOINT=https://test.tccloud.io
|
|
99
|
+
export TEQCONNECT_ACCESS_KEY_ID=...
|
|
100
|
+
export TEQCONNECT_SECRET_ACCESS_KEY=...
|
|
101
|
+
teq whoami
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
`TEQCONNECT_SESSION_TOKEN` and `TEQCONNECT_CREDENTIALS` (JSON with `access_key_id` and `secret_access_key`) are the other env sources. A profile from `teq login` is the fallback.
|
|
105
|
+
|
|
106
|
+
## Related
|
|
107
|
+
|
|
108
|
+
| Package | Use it for |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| [`teqconnect`](https://pypi.org/project/teqconnect/) | The Python SDK this CLI calls |
|
|
111
|
+
| [`@teqconnect/sdk`](https://www.npmjs.com/package/@teqconnect/sdk) | The same API from Node.js |
|
|
112
|
+
| [`@teqconnect/express`](https://www.npmjs.com/package/@teqconnect/express) | Sign in with TeqConnect on Express |
|
|
113
|
+
|
|
114
|
+
Apache-2.0.
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling>=1.33.0"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "teqconnect-cli"
|
|
7
|
+
description = "The teq command-line interface for TeqConnect. Login, IoT, AI, webhooks, and VPN enrollment."
|
|
8
|
+
readme = "README.md"
|
|
9
|
+
keywords = ["teqconnect", "cli", "iot", "vpn", "webhooks"]
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = "Apache-2.0"
|
|
12
|
+
authors = [{ name = "IO-TEQ" }]
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Development Status :: 4 - Beta",
|
|
15
|
+
"Environment :: Console",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: Apache Software License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Topic :: Software Development :: Libraries",
|
|
23
|
+
]
|
|
24
|
+
dynamic = ["version"]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"teqconnect>=0.1,<0.2",
|
|
27
|
+
"typer>=0.29.2",
|
|
28
|
+
"rich>=15.0.0",
|
|
29
|
+
"jmespath>=1.1.0",
|
|
30
|
+
"pyyaml>=6.0.3",
|
|
31
|
+
"cryptography>=50.0.2",
|
|
32
|
+
]
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
teq = "teqconnect_cli.main:app"
|
|
36
|
+
|
|
37
|
+
[tool.uv.sources]
|
|
38
|
+
teqconnect = { workspace = true }
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
testpaths = ["tests"]
|
|
42
|
+
|
|
43
|
+
[tool.hatch.version]
|
|
44
|
+
path = "teqconnect_cli/_version.py"
|
|
45
|
+
|
|
46
|
+
[tool.hatch.build.targets.wheel]
|
|
47
|
+
packages = ["teqconnect_cli"]
|
|
48
|
+
|
|
49
|
+
[tool.hatch.build.targets.sdist]
|
|
50
|
+
include = ["teqconnect_cli", "README.md"]
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"""teqconnect-cli: the ``teq`` command-line interface.
|
|
2
|
+
|
|
3
|
+
Every command is one call into the Python ``teqconnect`` SDK. This package never
|
|
4
|
+
imports ``httpx``, ``websockets``, or ``socket``: the SDK owns the only HTTP and
|
|
5
|
+
WebSocket paths.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from ._version import __version__
|
|
9
|
+
|
|
10
|
+
__all__ = ["__version__"]
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""Output rendering and the shared CLI state.
|
|
2
|
+
|
|
3
|
+
``emit`` unwraps the SDK return value, applies the ``--query`` JMESPath, and
|
|
4
|
+
prints it in the ``--output`` format. The value handed here is already the
|
|
5
|
+
unwrapped ``data`` (the SDK pipeline unwraps the envelope), so there is no
|
|
6
|
+
second HTTP call and no second unwrap. ``rich`` renders the table.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
import json
|
|
12
|
+
import sys
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from typing import Any
|
|
15
|
+
|
|
16
|
+
import jmespath
|
|
17
|
+
import yaml
|
|
18
|
+
from rich.console import Console
|
|
19
|
+
from rich.table import Table
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class State:
|
|
24
|
+
profile: str = "default"
|
|
25
|
+
endpoint: str | None = None
|
|
26
|
+
output: str = "json"
|
|
27
|
+
query: str | None = None
|
|
28
|
+
debug: bool = False
|
|
29
|
+
org: str | None = None
|
|
30
|
+
extra: dict[str, Any] = field(default_factory=dict)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
# One module-level state object; the Typer callback fills it before a command runs.
|
|
34
|
+
state = State()
|
|
35
|
+
|
|
36
|
+
_console = Console()
|
|
37
|
+
_err = Console(stderr=True)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def emit(value: Any, st: State) -> None:
|
|
41
|
+
"""Render ``value`` to stdout in the selected format after ``--query``."""
|
|
42
|
+
if st.query:
|
|
43
|
+
value = jmespath.search(st.query, value)
|
|
44
|
+
fmt = (st.output or "json").lower()
|
|
45
|
+
if fmt == "json":
|
|
46
|
+
_print_json(value)
|
|
47
|
+
elif fmt == "yaml":
|
|
48
|
+
_print_yaml(value)
|
|
49
|
+
elif fmt == "table":
|
|
50
|
+
_print_table(value)
|
|
51
|
+
elif fmt == "text":
|
|
52
|
+
_print_text(value)
|
|
53
|
+
else: # Unknown --output is bad usage.
|
|
54
|
+
_err.print(f"unknown --output: {st.output}")
|
|
55
|
+
raise SystemExit(2)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def debug(message: str, st: State) -> None:
|
|
59
|
+
"""Write a diagnostic line to stderr when ``--debug`` is set."""
|
|
60
|
+
if st.debug:
|
|
61
|
+
_err.print(f"[dim]debug:[/dim] {message}")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _print_json(value: Any) -> None:
|
|
65
|
+
sys.stdout.write(json.dumps(value, indent=2, default=str, sort_keys=False) + "\n")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def _print_yaml(value: Any) -> None:
|
|
69
|
+
sys.stdout.write(yaml.safe_dump(_plain(value), sort_keys=False, default_flow_style=False))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _print_text(value: Any) -> None:
|
|
73
|
+
if isinstance(value, (dict, list)):
|
|
74
|
+
sys.stdout.write(json.dumps(value, default=str) + "\n")
|
|
75
|
+
elif value is None:
|
|
76
|
+
sys.stdout.write("\n")
|
|
77
|
+
else:
|
|
78
|
+
sys.stdout.write(str(value) + "\n")
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def _print_table(value: Any) -> None:
|
|
82
|
+
rows = value if isinstance(value, list) else [value]
|
|
83
|
+
rows = [r for r in rows if isinstance(r, dict)]
|
|
84
|
+
if not rows:
|
|
85
|
+
_print_text(value)
|
|
86
|
+
return
|
|
87
|
+
columns: list[str] = []
|
|
88
|
+
for row in rows:
|
|
89
|
+
for key in row:
|
|
90
|
+
if key not in columns:
|
|
91
|
+
columns.append(key)
|
|
92
|
+
table = Table(show_header=True, header_style="bold")
|
|
93
|
+
for column in columns:
|
|
94
|
+
table.add_column(column)
|
|
95
|
+
for row in rows:
|
|
96
|
+
table.add_row(*[_cell(row.get(column)) for column in columns])
|
|
97
|
+
_console.print(table)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _cell(value: Any) -> str:
|
|
101
|
+
if value is None:
|
|
102
|
+
return ""
|
|
103
|
+
if isinstance(value, (dict, list)):
|
|
104
|
+
return json.dumps(value, default=str)
|
|
105
|
+
return str(value)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _plain(value: Any) -> Any:
|
|
109
|
+
"""Coerce to plain containers so yaml does not emit Python object tags."""
|
|
110
|
+
if isinstance(value, dict):
|
|
111
|
+
return {k: _plain(v) for k, v in value.items()}
|
|
112
|
+
if isinstance(value, (list, tuple)):
|
|
113
|
+
return [_plain(v) for v in value]
|
|
114
|
+
if isinstance(value, (str, int, float, bool)) or value is None:
|
|
115
|
+
return value
|
|
116
|
+
return str(value)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.1.1"
|