adanos-cli 1.30.0__tar.gz → 1.31.0__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.
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/.github/workflows/ci.yml +3 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/CHANGELOG.md +21 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/PKG-INFO +30 -2
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/README.md +29 -1
- adanos_cli-1.31.0/scripts/cli_audit.py +58 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/__init__.py +1 -1
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/activity_log.py +5 -2
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/commands/auth.py +2 -14
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/commands/config.py +3 -1
- adanos_cli-1.31.0/src/adanos_cli/commands/secrets.py +54 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/config.py +17 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/main.py +385 -77
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/nlp.py +27 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/summaries.py +87 -2
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/tty.py +6 -1
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_activity_log.py +16 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_agent_contract.py +130 -1
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_auth.py +88 -2
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_diagnostics.py +59 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_endpoint_coverage.py +31 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_onboarding.py +14 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_power_features.py +125 -2
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_tty.py +18 -1
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/.github/workflows/cli-binaries.yml +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/.github/workflows/publish-pypi.yml +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/.gitignore +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/LICENSE +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/install.ps1 +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/install.sh +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/pyproject.toml +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/scripts/build_cli_binary.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/scripts/generate_homebrew_formula.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/scripts/pyinstaller_entrypoint.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/__main__.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/commands/__init__.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/commands/extensions.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/endpoints.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/shell_history.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/update_notifier.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/utils.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/src/adanos_cli/watchlists.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/__init__.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/conftest.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_account.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_config_runtime.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_distribution.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_extensions.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_logs.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_shell.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_update_notifier.py +0 -0
- {adanos_cli-1.30.0 → adanos_cli-1.31.0}/tests/test_watchlists.py +0 -0
|
@@ -5,6 +5,27 @@ All notable changes to `adanos-cli` will be documented in this file.
|
|
|
5
5
|
Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
|
|
6
6
|
Versioning: [Semantic Versioning](https://semver.org/spec/v2.0.0.html)
|
|
7
7
|
|
|
8
|
+
## [1.31.0] - 2026-07-03
|
|
9
|
+
|
|
10
|
+
### Added
|
|
11
|
+
- Added explicit `--no-color`, `--no-input`, and `--plain` global flags.
|
|
12
|
+
- Added `--api-key-stdin` and `--api-key-file` for `login`, `auth login`, and `config set`.
|
|
13
|
+
- Added grouped and filterable `adanos endpoint list --platform ... --search ...`.
|
|
14
|
+
- Added an offline CLI audit script and CI step for stable help/output contracts.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
- Synced CLI human reports with Adanos Market Sentiment API `1.46.0`, including Polymarket `pulse`, representative `top_mentions` evidence, `market_status`, `daily_trend[].bullish_pct` / `bearish_pct`, and clearer `market_count` vs `current_market_count` breadth labels.
|
|
18
|
+
- Human output for endpoint-backed commands such as `trending`, `search`, `compare`, `stats`, `health`, and `endpoint call` now uses compact summaries/tables. Use `--json` or `--output json` for raw payloads.
|
|
19
|
+
- JSON report outputs now consistently include `kind` and `command`, with `subcommand` where relevant.
|
|
20
|
+
- Help output for `trending`, `endpoint call`, `watchlist`, `export`, and `scan` now starts from concrete examples.
|
|
21
|
+
- `capabilities` now documents output modes, secret input methods, config paths, exit codes, and the JSON contract.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
- Fixed `adanos ask` routing so common crypto prompts such as `How does BTC look?`, `How does ETH look?`, `How does SOL look?`, and `compare BTC and ETH` use crypto report/compare flows instead of stock reports.
|
|
25
|
+
- Fixed `--output text` so explicit text mode is respected even when stdout is redirected.
|
|
26
|
+
- Replaced raw connection-refused runtime errors with a concise API base URL/network/proxy hint.
|
|
27
|
+
- `doctor` now reports corrupt `config.json` or `credentials.json` instead of silently treating them as empty.
|
|
28
|
+
|
|
8
29
|
## [1.30.0] - 2026-06-23
|
|
9
30
|
|
|
10
31
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: adanos-cli
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.31.0
|
|
4
4
|
Summary: CLI for the Adanos Market Sentiment API
|
|
5
5
|
Project-URL: Homepage, https://adanos.org
|
|
6
6
|
Project-URL: API_Docs, https://api.adanos.org/docs
|
|
@@ -135,6 +135,8 @@ Persist a key locally:
|
|
|
135
135
|
|
|
136
136
|
```bash
|
|
137
137
|
adanos login --api-key sk_live_xxx
|
|
138
|
+
printf '%s\n' "$ADANOS_API_KEY" | adanos login --api-key-stdin
|
|
139
|
+
adanos login --api-key-file ~/.config/adanos-cli/key.txt
|
|
138
140
|
```
|
|
139
141
|
|
|
140
142
|
Request a recovery email for an existing account:
|
|
@@ -165,6 +167,14 @@ Priority order:
|
|
|
165
167
|
- `ADANOS_API_KEY`
|
|
166
168
|
- stored credentials in the active profile
|
|
167
169
|
|
|
170
|
+
Recommended secret input for automation is `--api-key-stdin` or `--api-key-file`. `--api-key` and `ADANOS_API_KEY` remain supported, but they are easier to leak through shell history or process inspection.
|
|
171
|
+
|
|
172
|
+
Use `--no-input` in CI or agents to make missing prompts fail fast:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
adanos --no-input login --api-key-stdin
|
|
176
|
+
```
|
|
177
|
+
|
|
168
178
|
## Common Workflows
|
|
169
179
|
|
|
170
180
|
Stock report:
|
|
@@ -197,6 +207,8 @@ Raw endpoint access:
|
|
|
197
207
|
|
|
198
208
|
```bash
|
|
199
209
|
adanos endpoint list
|
|
210
|
+
adanos endpoint list --platform polymarket-stocks
|
|
211
|
+
adanos endpoint list --search mentions
|
|
200
212
|
adanos endpoint call root.health
|
|
201
213
|
adanos endpoint call reddit-stocks.trending --limit 10
|
|
202
214
|
adanos endpoint call reddit-stocks.market-sentiment --from 2026-05-01 --to 2026-05-07
|
|
@@ -206,12 +218,13 @@ adanos endpoint call sentiment.analyze --text "TSLA looks like a short squeeze s
|
|
|
206
218
|
```
|
|
207
219
|
|
|
208
220
|
Polymarket endpoint output includes both `market_count` for selected-window breadth and `current_market_count` for live-only active-market breadth.
|
|
221
|
+
For API `1.45.1+`, Polymarket `top_mentions` in stock detail output are representative sentiment evidence, not a liquidity leaderboard. When market status is available, the CLI shows `market_status` alongside the evidence. For API `1.46.0+`, human summaries prefer `daily_trend[].bullish_pct` and `daily_trend[].bearish_pct` over deprecated positive/negative/neutral count fields.
|
|
209
222
|
|
|
210
223
|
Period-capable commands and endpoint calls accept `--from YYYY-MM-DD` and `--to YYYY-MM-DD` as inclusive UTC date windows. `--days N` remains available for v1 compatibility, but is legacy; combining `--from`, `--to` and `--days` returns API validation error `422`. Search commands are the exception: they accept only `--limit` and use the API-managed recent summary window.
|
|
211
224
|
|
|
212
225
|
## AI / Automation
|
|
213
226
|
|
|
214
|
-
The CLI supports machine-readable output via `--output json` or `--quiet`.
|
|
227
|
+
The CLI supports explicit machine-readable output via `--output json` or `--quiet`.
|
|
215
228
|
|
|
216
229
|
```bash
|
|
217
230
|
adanos --quiet capabilities
|
|
@@ -221,10 +234,25 @@ adanos --quiet ask "How does TSLA look?"
|
|
|
221
234
|
adanos --quiet endpoint call news-stocks.trending --limit 3
|
|
222
235
|
```
|
|
223
236
|
|
|
237
|
+
Output modes:
|
|
238
|
+
- default auto: human text on a TTY, JSON when stdout is piped
|
|
239
|
+
- `--output text`: force human text, even when stdout is redirected
|
|
240
|
+
- `--plain`: force plain text and disable auto JSON
|
|
241
|
+
- `--output json`, `--json`, or `--quiet`: force JSON
|
|
242
|
+
- `--no-color`: disable ANSI color output; `NO_COLOR=1` is also honored
|
|
243
|
+
|
|
224
244
|
JSON conventions:
|
|
225
245
|
- object payloads include a stable `kind`
|
|
226
246
|
- command wrappers include `command`, and `subcommand` when relevant
|
|
227
247
|
- endpoint-backed payloads include `platform`, `route`, `endpoint`, `path`, and `data`
|
|
248
|
+
- raw endpoint payloads are available with `--json` / `--output json`; human mode prints compact tables or summaries
|
|
249
|
+
|
|
250
|
+
Exit codes:
|
|
251
|
+
- `0`: success
|
|
252
|
+
- `1`: runtime or network/API failure
|
|
253
|
+
- `2`: usage, auth, or missing configuration error
|
|
254
|
+
|
|
255
|
+
This CLI is a research and workflow tool, not investment advice.
|
|
228
256
|
|
|
229
257
|
## Diagnostics
|
|
230
258
|
|
|
@@ -109,6 +109,8 @@ Persist a key locally:
|
|
|
109
109
|
|
|
110
110
|
```bash
|
|
111
111
|
adanos login --api-key sk_live_xxx
|
|
112
|
+
printf '%s\n' "$ADANOS_API_KEY" | adanos login --api-key-stdin
|
|
113
|
+
adanos login --api-key-file ~/.config/adanos-cli/key.txt
|
|
112
114
|
```
|
|
113
115
|
|
|
114
116
|
Request a recovery email for an existing account:
|
|
@@ -139,6 +141,14 @@ Priority order:
|
|
|
139
141
|
- `ADANOS_API_KEY`
|
|
140
142
|
- stored credentials in the active profile
|
|
141
143
|
|
|
144
|
+
Recommended secret input for automation is `--api-key-stdin` or `--api-key-file`. `--api-key` and `ADANOS_API_KEY` remain supported, but they are easier to leak through shell history or process inspection.
|
|
145
|
+
|
|
146
|
+
Use `--no-input` in CI or agents to make missing prompts fail fast:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
adanos --no-input login --api-key-stdin
|
|
150
|
+
```
|
|
151
|
+
|
|
142
152
|
## Common Workflows
|
|
143
153
|
|
|
144
154
|
Stock report:
|
|
@@ -171,6 +181,8 @@ Raw endpoint access:
|
|
|
171
181
|
|
|
172
182
|
```bash
|
|
173
183
|
adanos endpoint list
|
|
184
|
+
adanos endpoint list --platform polymarket-stocks
|
|
185
|
+
adanos endpoint list --search mentions
|
|
174
186
|
adanos endpoint call root.health
|
|
175
187
|
adanos endpoint call reddit-stocks.trending --limit 10
|
|
176
188
|
adanos endpoint call reddit-stocks.market-sentiment --from 2026-05-01 --to 2026-05-07
|
|
@@ -180,12 +192,13 @@ adanos endpoint call sentiment.analyze --text "TSLA looks like a short squeeze s
|
|
|
180
192
|
```
|
|
181
193
|
|
|
182
194
|
Polymarket endpoint output includes both `market_count` for selected-window breadth and `current_market_count` for live-only active-market breadth.
|
|
195
|
+
For API `1.45.1+`, Polymarket `top_mentions` in stock detail output are representative sentiment evidence, not a liquidity leaderboard. When market status is available, the CLI shows `market_status` alongside the evidence. For API `1.46.0+`, human summaries prefer `daily_trend[].bullish_pct` and `daily_trend[].bearish_pct` over deprecated positive/negative/neutral count fields.
|
|
183
196
|
|
|
184
197
|
Period-capable commands and endpoint calls accept `--from YYYY-MM-DD` and `--to YYYY-MM-DD` as inclusive UTC date windows. `--days N` remains available for v1 compatibility, but is legacy; combining `--from`, `--to` and `--days` returns API validation error `422`. Search commands are the exception: they accept only `--limit` and use the API-managed recent summary window.
|
|
185
198
|
|
|
186
199
|
## AI / Automation
|
|
187
200
|
|
|
188
|
-
The CLI supports machine-readable output via `--output json` or `--quiet`.
|
|
201
|
+
The CLI supports explicit machine-readable output via `--output json` or `--quiet`.
|
|
189
202
|
|
|
190
203
|
```bash
|
|
191
204
|
adanos --quiet capabilities
|
|
@@ -195,10 +208,25 @@ adanos --quiet ask "How does TSLA look?"
|
|
|
195
208
|
adanos --quiet endpoint call news-stocks.trending --limit 3
|
|
196
209
|
```
|
|
197
210
|
|
|
211
|
+
Output modes:
|
|
212
|
+
- default auto: human text on a TTY, JSON when stdout is piped
|
|
213
|
+
- `--output text`: force human text, even when stdout is redirected
|
|
214
|
+
- `--plain`: force plain text and disable auto JSON
|
|
215
|
+
- `--output json`, `--json`, or `--quiet`: force JSON
|
|
216
|
+
- `--no-color`: disable ANSI color output; `NO_COLOR=1` is also honored
|
|
217
|
+
|
|
198
218
|
JSON conventions:
|
|
199
219
|
- object payloads include a stable `kind`
|
|
200
220
|
- command wrappers include `command`, and `subcommand` when relevant
|
|
201
221
|
- endpoint-backed payloads include `platform`, `route`, `endpoint`, `path`, and `data`
|
|
222
|
+
- raw endpoint payloads are available with `--json` / `--output json`; human mode prints compact tables or summaries
|
|
223
|
+
|
|
224
|
+
Exit codes:
|
|
225
|
+
- `0`: success
|
|
226
|
+
- `1`: runtime or network/API failure
|
|
227
|
+
- `2`: usage, auth, or missing configuration error
|
|
228
|
+
|
|
229
|
+
This CLI is a research and workflow tool, not investment advice.
|
|
202
230
|
|
|
203
231
|
## Diagnostics
|
|
204
232
|
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""Offline smoke audit for the installed adanos CLI."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import shutil
|
|
7
|
+
import subprocess
|
|
8
|
+
import sys
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def _command() -> list[str]:
|
|
12
|
+
adanos = shutil.which("adanos")
|
|
13
|
+
if adanos:
|
|
14
|
+
return [adanos]
|
|
15
|
+
return [sys.executable, "-m", "adanos_cli"]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _run(*args: str) -> subprocess.CompletedProcess[str]:
|
|
19
|
+
return subprocess.run([*_command(), *args], text=True, capture_output=True, check=False)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _assert_ok(name: str, result: subprocess.CompletedProcess[str]) -> None:
|
|
23
|
+
if result.returncode != 0:
|
|
24
|
+
raise AssertionError(f"{name} failed with rc={result.returncode}: {result.stderr or result.stdout}")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def main() -> int:
|
|
28
|
+
capabilities = _run("--output", "json", "capabilities")
|
|
29
|
+
_assert_ok("capabilities json", capabilities)
|
|
30
|
+
payload = json.loads(capabilities.stdout)
|
|
31
|
+
assert payload["kind"] == "capabilities"
|
|
32
|
+
assert payload["command"] == "capabilities"
|
|
33
|
+
assert "auto" in payload["output_modes"]
|
|
34
|
+
assert "--api-key-stdin" in payload["auth"]["secret_input"]
|
|
35
|
+
|
|
36
|
+
text_capabilities = _run("--output", "text", "capabilities")
|
|
37
|
+
_assert_ok("capabilities text", text_capabilities)
|
|
38
|
+
assert text_capabilities.stdout.startswith("CLI capabilities")
|
|
39
|
+
assert not text_capabilities.stdout.lstrip().startswith("{")
|
|
40
|
+
|
|
41
|
+
endpoint_list = _run("endpoint", "list", "--platform", "polymarket-stocks", "--search", "stock", "--json")
|
|
42
|
+
_assert_ok("endpoint list json", endpoint_list)
|
|
43
|
+
endpoints = json.loads(endpoint_list.stdout)
|
|
44
|
+
assert endpoints
|
|
45
|
+
assert all(row["id"].startswith("polymarket-stocks") for row in endpoints)
|
|
46
|
+
|
|
47
|
+
help_result = _run("trending", "--help")
|
|
48
|
+
_assert_ok("trending help", help_result)
|
|
49
|
+
assert "Examples:" in help_result.stdout
|
|
50
|
+
|
|
51
|
+
unknown = _run("wat")
|
|
52
|
+
assert unknown.returncode == 2
|
|
53
|
+
assert "hint:" in unknown.stderr
|
|
54
|
+
return 0
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
if __name__ == "__main__":
|
|
58
|
+
raise SystemExit(main())
|
|
@@ -26,13 +26,16 @@ def sanitize_argv(argv: list[str]) -> list[str]:
|
|
|
26
26
|
sanitized.append("<redacted>")
|
|
27
27
|
redact_next = False
|
|
28
28
|
continue
|
|
29
|
-
if token
|
|
29
|
+
if token in {"--api-key", "--api-key-file"}:
|
|
30
30
|
sanitized.append(token)
|
|
31
31
|
redact_next = True
|
|
32
32
|
continue
|
|
33
33
|
if token.startswith("--api-key="):
|
|
34
34
|
sanitized.append("--api-key=<redacted>")
|
|
35
35
|
continue
|
|
36
|
+
if token.startswith("--api-key-file="):
|
|
37
|
+
sanitized.append("--api-key-file=<redacted>")
|
|
38
|
+
continue
|
|
36
39
|
sanitized.append(token)
|
|
37
40
|
|
|
38
41
|
if redact_next:
|
|
@@ -41,7 +44,7 @@ def sanitize_argv(argv: list[str]) -> list[str]:
|
|
|
41
44
|
|
|
42
45
|
|
|
43
46
|
def _command_name(argv: list[str]) -> str | None:
|
|
44
|
-
value_flags = {"--api-key", "--base-url", "--output"}
|
|
47
|
+
value_flags = {"--api-key", "--api-key-file", "--base-url", "--output"}
|
|
45
48
|
skip_next = False
|
|
46
49
|
for token in argv:
|
|
47
50
|
if skip_next:
|
|
@@ -2,20 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from getpass import getpass
|
|
6
5
|
from argparse import Namespace
|
|
7
6
|
|
|
8
7
|
from .. import config as cli_config
|
|
9
8
|
from ..config import DEFAULT_BASE_URL, load_config_file, masked_key, save_config_file
|
|
9
|
+
from .secrets import read_api_key_arg
|
|
10
10
|
from ..utils import CliUsageError, print_json, with_json_metadata
|
|
11
|
-
from ..tty import is_interactive
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
def _prompt_api_key() -> str:
|
|
15
|
-
value = getpass("API key: ").strip()
|
|
16
|
-
if not value:
|
|
17
|
-
raise CliUsageError("API key must not be empty.")
|
|
18
|
-
return value
|
|
19
11
|
|
|
20
12
|
|
|
21
13
|
def handle_auth_command(args: Namespace) -> int:
|
|
@@ -25,11 +17,7 @@ def handle_auth_command(args: Namespace) -> int:
|
|
|
25
17
|
validation_error = cli_config.validate_profile_name(profile_name)
|
|
26
18
|
if validation_error:
|
|
27
19
|
raise CliUsageError(validation_error)
|
|
28
|
-
api_key =
|
|
29
|
-
if not api_key:
|
|
30
|
-
if not is_interactive():
|
|
31
|
-
raise CliUsageError("Non-interactive usage requires --api-key.")
|
|
32
|
-
api_key = _prompt_api_key()
|
|
20
|
+
api_key = read_api_key_arg(args)
|
|
33
21
|
save_config_file(
|
|
34
22
|
api_key=api_key,
|
|
35
23
|
base_url=args.base_url,
|
|
@@ -6,13 +6,15 @@ from argparse import Namespace
|
|
|
6
6
|
|
|
7
7
|
from .. import config as cli_config
|
|
8
8
|
from ..config import DEFAULT_BASE_URL, clear_config_file, load_config_file, masked_key, save_config_file
|
|
9
|
+
from .secrets import read_api_key_arg
|
|
9
10
|
from ..utils import CliUsageError, print_json, with_json_metadata
|
|
10
11
|
|
|
11
12
|
|
|
12
13
|
def handle_config_command(args: Namespace) -> int:
|
|
13
14
|
if args._handler == "config_set":
|
|
15
|
+
api_key = read_api_key_arg(args)
|
|
14
16
|
save_config_file(
|
|
15
|
-
api_key=
|
|
17
|
+
api_key=api_key,
|
|
16
18
|
base_url=args.base_url,
|
|
17
19
|
profile_name=getattr(args, "profile", None),
|
|
18
20
|
)
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"""Secret input helpers for command handlers."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import sys
|
|
6
|
+
from argparse import Namespace
|
|
7
|
+
from getpass import getpass
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from ..tty import is_interactive, stdin_is_tty
|
|
11
|
+
from ..utils import CliUsageError
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def read_api_key_arg(args: Namespace) -> str:
|
|
15
|
+
sources = [
|
|
16
|
+
name
|
|
17
|
+
for name in ("api_key", "api_key_file", "api_key_stdin")
|
|
18
|
+
if bool(getattr(args, name, None))
|
|
19
|
+
]
|
|
20
|
+
if len(sources) > 1:
|
|
21
|
+
raise CliUsageError("Use only one API key input source: --api-key, --api-key-file, or --api-key-stdin.")
|
|
22
|
+
|
|
23
|
+
api_key = str(getattr(args, "api_key", "") or "").strip()
|
|
24
|
+
if api_key:
|
|
25
|
+
return api_key
|
|
26
|
+
|
|
27
|
+
api_key_file = str(getattr(args, "api_key_file", "") or "").strip()
|
|
28
|
+
if api_key_file:
|
|
29
|
+
try:
|
|
30
|
+
value = Path(api_key_file).expanduser().read_text(encoding="utf-8").strip()
|
|
31
|
+
except (OSError, UnicodeDecodeError) as exc:
|
|
32
|
+
raise CliUsageError(f"Could not read API key file: {exc}") from exc
|
|
33
|
+
if not value:
|
|
34
|
+
raise CliUsageError("API key file is empty.")
|
|
35
|
+
return value
|
|
36
|
+
|
|
37
|
+
if bool(getattr(args, "api_key_stdin", False)):
|
|
38
|
+
if bool(getattr(args, "no_input", False)) and stdin_is_tty():
|
|
39
|
+
raise CliUsageError("Cannot read --api-key-stdin with --no-input from an interactive TTY.")
|
|
40
|
+
value = sys.stdin.readline().strip()
|
|
41
|
+
if not value:
|
|
42
|
+
raise CliUsageError("No API key received on stdin.")
|
|
43
|
+
return value
|
|
44
|
+
|
|
45
|
+
if bool(getattr(args, "no_input", False)):
|
|
46
|
+
raise CliUsageError("API key required with --no-input. Use --api-key-stdin or --api-key-file.")
|
|
47
|
+
|
|
48
|
+
if not is_interactive():
|
|
49
|
+
raise CliUsageError("Non-interactive usage requires --api-key, --api-key-file, or --api-key-stdin.")
|
|
50
|
+
|
|
51
|
+
value = getpass("API key: ").strip()
|
|
52
|
+
if not value:
|
|
53
|
+
raise CliUsageError("API key must not be empty.")
|
|
54
|
+
return value
|
|
@@ -40,6 +40,23 @@ class RuntimeConfig:
|
|
|
40
40
|
profile_name: str | None = None
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
def inspect_json_file(path: Path) -> dict[str, Any]:
|
|
44
|
+
if not path.exists():
|
|
45
|
+
return {"path": str(path), "exists": False, "ok": True, "error": None}
|
|
46
|
+
try:
|
|
47
|
+
payload = json.loads(path.read_text(encoding="utf-8"))
|
|
48
|
+
except Exception as exc:
|
|
49
|
+
return {"path": str(path), "exists": True, "ok": False, "error": str(exc)}
|
|
50
|
+
if not isinstance(payload, dict):
|
|
51
|
+
return {
|
|
52
|
+
"path": str(path),
|
|
53
|
+
"exists": True,
|
|
54
|
+
"ok": False,
|
|
55
|
+
"error": "JSON root must be an object",
|
|
56
|
+
}
|
|
57
|
+
return {"path": str(path), "exists": True, "ok": True, "error": None}
|
|
58
|
+
|
|
59
|
+
|
|
43
60
|
def _read_json_file(path: Path) -> dict[str, Any]:
|
|
44
61
|
if not path.exists():
|
|
45
62
|
return {}
|