@kill-switch/cli 0.3.1 → 0.3.3

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.
@@ -101,8 +101,12 @@ export function registerAuthCommands(program, createClient) {
101
101
  .option("--api-key <key>", "Personal API key (starts with ks_) — skips browser flow")
102
102
  .action(async (opts) => {
103
103
  const json = program.opts().json;
104
- const apiUrl = resolveApiUrl();
105
- let key = opts.apiKey;
104
+ const apiUrl = resolveApiUrl(program.opts().apiUrl);
105
+ // The program also declares a global --api-key/--api-url; by commander's
106
+ // parent/child precedence the value lands on the PARENT even when passed
107
+ // after `login`, leaving opts.apiKey undefined. Read from either place so
108
+ // `ks auth login --api-key KEY` actually works.
109
+ let key = opts.apiKey ?? program.opts().apiKey;
106
110
  // Device flow when no --api-key. JSON mode requires --api-key (no browser).
107
111
  if (!key) {
108
112
  if (json) {
package/dist/index.js CHANGED
@@ -13,6 +13,7 @@
13
13
  import { Command } from "commander";
14
14
  import { KillSwitchClient } from "@kill-switch/sdk";
15
15
  import { resolveApiKey, resolveApiUrl } from "./config.js";
16
+ import { outputError } from "./output.js";
16
17
  import { registerAuthCommands } from "./commands/auth.js";
17
18
  import { registerAccountCommands } from "./commands/accounts.js";
18
19
  import { registerRuleCommands } from "./commands/rules.js";
@@ -45,10 +46,19 @@ program
45
46
  */
46
47
  const createClient = () => {
47
48
  const opts = program.opts();
48
- return new KillSwitchClient({
49
- apiKey: resolveApiKey(opts.apiKey),
50
- baseUrl: resolveApiUrl(opts.apiUrl),
51
- });
49
+ try {
50
+ return new KillSwitchClient({
51
+ apiKey: resolveApiKey(opts.apiKey),
52
+ baseUrl: resolveApiUrl(opts.apiUrl),
53
+ });
54
+ }
55
+ catch (err) {
56
+ // e.g. a malformed / non-https apiUrl from config/env (resolveApiUrl throws).
57
+ // Some commands build the client outside their try/catch, so handle it here
58
+ // to emit a clean error instead of a raw stack trace.
59
+ outputError(err instanceof Error ? err.message : String(err), opts.json);
60
+ process.exit(1);
61
+ }
52
62
  };
53
63
  registerAuthCommands(program, createClient);
54
64
  registerAccountCommands(program, createClient);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kill-switch/cli",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
4
4
  "description": "Kill Switch CLI — monitor cloud spending, kill runaway services from the terminal",
5
5
  "type": "module",
6
6
  "bin": {