@newly/cli 0.1.106 → 0.1.108

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.
@@ -99,7 +99,7 @@ export function consumeSimulatorLogSse(raw) {
99
99
  function writeSimulatorLogEntry(entry, json) {
100
100
  console.log(json ? JSON.stringify(entry) : entry.message);
101
101
  }
102
- function parseLabels(labels) {
102
+ function parseTags(labels) {
103
103
  const out = {};
104
104
  for (const raw of labels ?? []) {
105
105
  const idx = raw.indexOf('=');
@@ -307,7 +307,7 @@ async function createSimulatorSession(platform, opts) {
307
307
  model: opts.model,
308
308
  region: opts.region,
309
309
  displayName: opts.displayName,
310
- labels: parseLabels(opts.label),
310
+ tags: parseTags(opts.label),
311
311
  installAssets,
312
312
  inactivityTimeout: opts.inactivityTimeout,
313
313
  hardTimeout: opts.hardTimeout,
@@ -263,6 +263,33 @@ function secretSelector(opts) {
263
263
  function collectRepeatable(value, previous) {
264
264
  return [...previous, value];
265
265
  }
266
+ export function parseTagPairs(values) {
267
+ return values.map((raw) => {
268
+ const at = raw.indexOf('=');
269
+ if (at <= 0) {
270
+ throw new Error(`--tag must be key=value (got ${JSON.stringify(raw)})`);
271
+ }
272
+ return [raw.slice(0, at), raw.slice(at + 1)];
273
+ });
274
+ }
275
+ export async function resolveSandboxByTag(api, tags) {
276
+ if (tags.length === 0) {
277
+ throw new Error('Provide a sandbox id, or --tag key=value to find one.');
278
+ }
279
+ const query = new URLSearchParams();
280
+ for (const [key, value] of parseTagPairs(tags))
281
+ query.append('tag', `${key}:${value}`);
282
+ const data = await api.get(`/run-cloud/sandboxes?${query}`);
283
+ const items = data?.items ?? [];
284
+ if (items.length === 0) {
285
+ throw new Error(`No sandbox matches ${tags.join(' ')}.`);
286
+ }
287
+ if (items.length > 1) {
288
+ const listed = items.map((s) => ` ${s.id}${s.name ? ` ${s.name}` : ''}`).join('\n');
289
+ throw new Error(`${items.length} sandboxes match ${tags.join(' ')} — narrow it, or pass an id:\n${listed}`);
290
+ }
291
+ return items[0].id;
292
+ }
266
293
  export function registerSandbox(program) {
267
294
  const sandbox = program.command('sandbox').description('Spawn and control microVM sandboxes');
268
295
  const defaultHelp = new Help();
@@ -362,12 +389,16 @@ export function registerSandbox(program) {
362
389
  .command('list')
363
390
  .description('List sandboxes')
364
391
  .option('--state <state>', 'filter by state')
365
- .option('--name <name>', 'filter by name (exact)')).action((opts) => run(async () => {
392
+ .option('--name <name>', 'filter by name (exact)')
393
+ .option('--tag <key=value>', 'filter by tag; repeatable, and a sandbox must carry every one', collectRepeatable, [])).action((opts) => run(async () => {
366
394
  const query = new URLSearchParams();
367
395
  if (opts.state)
368
396
  query.set('state', opts.state);
369
397
  if (opts.name)
370
398
  query.set('name', opts.name);
399
+ for (const [key, value] of parseTagPairs(opts.tag ?? [])) {
400
+ query.append('tag', `${key}:${value}`);
401
+ }
371
402
  const qs = query.size ? `?${query}` : '';
372
403
  const api = runCloudApi();
373
404
  const [data, boxes] = await Promise.all([
@@ -384,6 +415,23 @@ export function registerSandbox(program) {
384
415
  else
385
416
  console.log(renderSandboxList(items));
386
417
  }));
418
+ withOutput(sandbox
419
+ .command('tag')
420
+ .description('Set or remove tags on a sandbox')
421
+ .argument('<id>', 'sandbox id')
422
+ .argument('<pairs...>', 'key=value to set, or key= to remove')).action((id, pairs, opts) => run(async () => {
423
+ const tags = Object.fromEntries(parseTagPairs(pairs).map(([key, value]) => [key, value === '' ? null : value]));
424
+ const updated = await runCloudApi().patch(`/run-cloud/sandboxes/${encodeURIComponent(id)}/tags`, { tags });
425
+ if (opts.json)
426
+ printJson(updated);
427
+ else {
428
+ const applied = (updated?.tags ?? {});
429
+ const entries = Object.entries(applied);
430
+ console.log(entries.length === 0
431
+ ? `${id} now has no tags`
432
+ : `${id}\n${entries.map(([k, v]) => ` ${k}=${v}`).join('\n')}`);
433
+ }
434
+ }));
387
435
  withOutput(sandbox
388
436
  .command('get')
389
437
  .description('Inspect a sandbox, including its public hostname when exposed')
@@ -497,15 +545,17 @@ export function registerSandbox(program) {
497
545
  sandbox
498
546
  .command('shell')
499
547
  .description('Open an interactive shell (resumes paused sandboxes)')
500
- .argument('<id>', 'sandbox id')
501
- .action((id) => run(async () => {
548
+ .argument('[id]', 'sandbox id; omit when using --tag')
549
+ .option('--tag <key=value>', 'find the sandbox by tag instead of id; repeatable, must match exactly one', collectRepeatable, [])
550
+ .action((id, opts) => run(async () => {
502
551
  const credentials = requireCredentials();
503
552
  const api = new ApiClient(credentials.apiUrl, credentials.token);
504
- await prepareSandboxShell(api, id);
553
+ const sandboxId = id ?? (await resolveSandboxByTag(api, opts.tag ?? []));
554
+ await prepareSandboxShell(api, sandboxId);
505
555
  process.exitCode = await runSandboxShell({
506
556
  apiUrl: credentials.apiUrl,
507
557
  token: credentials.token,
508
- sandboxId: id,
558
+ sandboxId,
509
559
  });
510
560
  }));
511
561
  for (const lifecycle of [
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const CLI_VERSION = '0.1.106';
1
+ export const CLI_VERSION = '0.1.108';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newly/cli",
3
- "version": "0.1.106",
3
+ "version": "0.1.108",
4
4
  "description": "Develop, provision, and deploy Newly backends from your terminal",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",