diff --git a/packages/cli/src/commands/add.tsx b/packages/cli/src/commands/add.tsx index 2694779..bc2f139 100644 --- a/packages/cli/src/commands/add.tsx +++ b/packages/cli/src/commands/add.tsx @@ -85,6 +85,7 @@ export default class Add extends Command { static override examples = ['<%= config.bin %> <%= command.id %>'] static override flags = { + registry: Flags.string({char: 'r', description: 'override registry url'}), force: Flags.boolean({char: 'f', description: 'override the existing file'}), config: Flags.string({char: 'p', description: 'path to config'}), shared: Flags.string({char: 's', description: 'place for installation of shared.ts'}), @@ -108,7 +109,10 @@ export default class Add extends Command { } const loadRegistryOra = ora('Fetching registry...').start() - const unsafeRegistry = await getRegistry() + if (flags.registry) { + this.log(`Using ${flags.registry} for registry.`) + } + const unsafeRegistry = await getRegistry(flags.registry) if (!unsafeRegistry.ok) { loadRegistryOra.fail(unsafeRegistry.message) return diff --git a/packages/cli/src/commands/list.ts b/packages/cli/src/commands/list.ts index ea45423..788f063 100644 --- a/packages/cli/src/commands/list.ts +++ b/packages/cli/src/commands/list.ts @@ -2,7 +2,6 @@ import {Command, Flags} from '@oclif/core' import {getAvailableComponentNames, getRegistry, getComponentURL, getComponentRealname} from '../helpers/registry.js' import ora from 'ora' import treeify from 'treeify' -import {CONFIG_DEFAULT_PATH} from '../const.js' import {loadConfig, validateConfig} from '../helpers/config.js' import {getComponentsInstalled} from '../helpers/path.js' @@ -12,6 +11,7 @@ export default class List extends Command { static override examples = ['<%= config.bin %> <%= command.id %>'] static override flags = { + registry: Flags.string({char: 'r', description: 'override registry url'}), url: Flags.boolean({char: 'u', description: 'include component file URL'}), config: Flags.string({char: 'p', description: 'path to config'}), } @@ -25,7 +25,10 @@ export default class List extends Command { const loadedConfig = await validateConfig((message: string) => this.log(message), await loadConfig(flags.config)) registrySpinner.start() - const unsafeRegistry = await getRegistry() + if (flags.registry) { + this.log(`Using ${flags.registry} for registry.`) + } + const unsafeRegistry = await getRegistry(flags.registry) if (!unsafeRegistry.ok) { registrySpinner.fail(unsafeRegistry.message) return diff --git a/packages/cli/src/commands/search.tsx b/packages/cli/src/commands/search.tsx index cb79afd..a339125 100644 --- a/packages/cli/src/commands/search.tsx +++ b/packages/cli/src/commands/search.tsx @@ -1,4 +1,4 @@ -import {Command, Args} from '@oclif/core' +import {Command, Args, Flags} from '@oclif/core' import {render} from 'ink' import {SearchBox} from '../components/SearchBox.js' import {getAvailableComponentNames, getRegistry} from '../helpers/registry.js' @@ -9,14 +9,21 @@ export default class Search extends Command { query: Args.string({description: 'search query'}), } + static override flags = { + registry: Flags.string({char: 'r', description: 'override registry url'}) + } + static override description = 'Search components.' static override examples = ['<%= config.bin %> <%= command.id %>'] public async run(): Promise { - const {args} = await this.parse(Search) + const {args, flags} = await this.parse(Search) - const registryResult = await getRegistry() + if (flags.registry) { + this.log(`Using ${flags.registry} for registry.`) + } + const registryResult = await getRegistry(flags.registry) if (!registryResult.ok) { this.error(registryResult.message) } diff --git a/packages/cli/src/helpers/registry.ts b/packages/cli/src/helpers/registry.ts index dcecebd..e5ffd0f 100644 --- a/packages/cli/src/helpers/registry.ts +++ b/packages/cli/src/helpers/registry.ts @@ -1,7 +1,7 @@ import {REGISTRY_URL, Registry} from '../const.js' -export async function getRegistry(): Promise<{ok: true; registry: Registry} | {ok: false; message: string}> { - const registryResponse = await fetch(REGISTRY_URL) +export async function getRegistry(REGISTRY_OVERRIDE_URL?: string): Promise<{ok: true; registry: Registry} | {ok: false; message: string}> { + const registryResponse = await fetch(REGISTRY_OVERRIDE_URL ?? REGISTRY_URL) if (registryResponse.ok) { return {