(
source: string,
options: { cowork?: boolean; sparse?: string[]; scope?: string },
)
| 445 | |
| 446 | // marketplace add (lines 5433–5487) |
| 447 | export async function marketplaceAddHandler( |
| 448 | source: string, |
| 449 | options: { cowork?: boolean; sparse?: string[]; scope?: string }, |
| 450 | ): Promise<void> { |
| 451 | if (options.cowork) setUseCoworkPlugins(true) |
| 452 | try { |
| 453 | const parsed = await parseMarketplaceInput(source) |
| 454 | |
| 455 | if (!parsed) { |
| 456 | cliError( |
| 457 | `${figures.cross} Invalid marketplace source format. Try: owner/repo, https://..., or ./path`, |
| 458 | ) |
| 459 | } |
| 460 | |
| 461 | if ('error' in parsed) { |
| 462 | cliError(`${figures.cross} ${parsed.error}`) |
| 463 | } |
| 464 | |
| 465 | // Validate scope |
| 466 | const scope = options.scope ?? 'user' |
| 467 | if (scope !== 'user' && scope !== 'project' && scope !== 'local') { |
| 468 | cliError( |
| 469 | `${figures.cross} Invalid scope '${scope}'. Use: user, project, or local`, |
| 470 | ) |
| 471 | } |
| 472 | const settingSource = scopeToSettingSource(scope) |
| 473 | |
| 474 | let marketplaceSource = parsed |
| 475 | |
| 476 | if (options.sparse && options.sparse.length > 0) { |
| 477 | if ( |
| 478 | marketplaceSource.source === 'github' || |
| 479 | marketplaceSource.source === 'git' |
| 480 | ) { |
| 481 | marketplaceSource = { |
| 482 | ...marketplaceSource, |
| 483 | sparsePaths: options.sparse, |
| 484 | } |
| 485 | } else { |
| 486 | cliError( |
| 487 | `${figures.cross} --sparse is only supported for github and git marketplace sources (got: ${marketplaceSource.source})`, |
| 488 | ) |
| 489 | } |
| 490 | } |
| 491 | |
| 492 | // biome-ignore lint/suspicious/noConsole:: intentional console output |
| 493 | console.log('Adding marketplace...') |
| 494 | |
| 495 | const { name, alreadyMaterialized, resolvedSource } = |
| 496 | await addMarketplaceSource(marketplaceSource, message => { |
| 497 | // biome-ignore lint/suspicious/noConsole:: intentional console output |
| 498 | console.log(message) |
| 499 | }) |
| 500 | |
| 501 | // Write intent to settings at the requested scope |
| 502 | saveMarketplaceToSettings(name, { source: resolvedSource }, settingSource) |
| 503 | |
| 504 | clearAllCaches() |
no test coverage detected