/** * Unified Selection Strategy Helper * * Provides consistent selection UI across all platforms (GitHub, JIRA, Azure DevOps) * for selecting repositories, projects, area paths, etc. * * Strategies: * - all: Select everything * - pattern-glob: Glob pattern matching (e.g., "sw-*", "*-backend") * - pattern-regex: Regular expression matching (e.g., "^sw-.*$") * - select-specific: Checkbox selection from list * - manual-entry: Comma-separated text input * * Pattern Shortcuts: * - "starts: prefix" → "prefix*" * - "ends: suffix" → "*suffix" * - "contains: text" → "*text*" * * @module cli/helpers/selection-strategy */ import type { SupportedLanguage } from '../../core/i18n/types.js'; /** * Selection strategy options */ export type SelectionStrategy = 'all' | 'pattern-glob' | 'pattern-regex' | 'select-specific' | 'manual-entry'; /** * Generic selectable item interface */ export interface SelectableItem { /** Display name for the item */ name: string; /** Unique identifier/value */ value: string; /** Optional: full path or additional context */ path?: string; /** Optional: additional metadata */ metadata?: Record; } /** * Selection result */ export interface SelectionResult { /** Selected strategy */ strategy: SelectionStrategy; /** Selected items */ items: T[]; /** Pattern used (for pattern strategies) */ pattern?: string; /** Whether selection was cancelled */ cancelled: boolean; } /** * Options for the selection prompt */ export interface SelectionPromptOptions { /** All available items to select from */ items: T[]; /** Type of items being selected (for display) */ itemType: 'repositories' | 'projects' | 'area paths' | 'boards' | 'items'; /** Optional: source/context name (e.g., org name, project name) */ sourceName?: string; /** Language for i18n */ language?: SupportedLanguage; /** Whether to show "All" option (default: true) */ showAllOption?: boolean; /** Whether to show preview before confirmation (default: true) */ showPreview?: boolean; /** Maximum items to show in preview (default: 20) */ previewLimit?: number; /** Custom validator for manual entry */ manualEntryValidator?: (value: string) => boolean | string; /** Whether to transform manual entry to uppercase (for JIRA keys) */ uppercaseManualEntry?: boolean; /** Field to match patterns against (default: 'name') */ matchField?: keyof T; } /** * Parse pattern shortcuts into glob/regex patterns * * Shortcuts: * - "starts: prefix" → "prefix*" (glob) * - "ends: suffix" → "*suffix" (glob) * - "contains: text" → "*text*" (glob) * - Raw patterns without glob chars are auto-expanded to prefix match: "sw-ecom" → "sw-ecom*" * * @param input - User input (may contain shortcuts) * @returns Parsed pattern */ export declare function parsePatternShortcut(input: string): string; /** * Match items by glob pattern * * @param items - Items to filter * @param pattern - Glob pattern (e.g., "sw-*", "*-backend") * @param field - Field to match against (default: 'name') * @returns Matching items */ export declare function matchByGlob(items: T[], pattern: string, field?: keyof T): T[]; /** * Match items by regular expression * * @param items - Items to filter * @param pattern - Regex pattern (e.g., "^sw-.*$") * @param field - Field to match against (default: 'name') * @returns Object with matching items or error */ export declare function matchByRegex(items: T[], pattern: string, field?: keyof T): { items: T[]; error?: string; }; /** * Validate regex pattern * * @param pattern - Pattern to validate * @returns True if valid, error message if invalid */ export declare function validateRegex(pattern: string): true | string; /** * Main selection prompt - unified across all platforms * * @param options - Selection options * @returns Selection result */ export declare function promptSelection(options: SelectionPromptOptions): Promise>; /** * Convert array of strings to SelectableItem array */ export declare function toSelectableItems(items: string[]): SelectableItem[]; /** * Convert array of objects with name/value to SelectableItem array */ export declare function toSelectableItemsFromObjects(items: T[], valueField?: keyof T): SelectableItem[]; /** * Clone pattern result (from repository-setup.ts) */ export interface ClonePatternResult { strategy: 'all' | 'pattern-glob' | 'pattern-regex' | 'manual' | 'skip'; pattern?: string; isRegex?: boolean; /** Explicitly selected repo names (for 'manual' strategy) */ selectedRepos?: string[]; } /** * Filter repositories by clone pattern * * Used during init to filter ADO/GitHub repos before cloning. * * @param repos - Array of repositories with name field * @param clonePattern - Clone pattern configuration * @returns Filtered repositories * * @example * ```typescript * const repos = [{ name: 'sw-fe' }, { name: 'sw-be' }, { name: 'other' }]; * const pattern = { strategy: 'pattern-glob', pattern: 'sw-*' }; * const filtered = filterRepositoriesByPattern(repos, pattern); * // Result: [{ name: 'sw-fe' }, { name: 'sw-be' }] * ``` */ export declare function filterRepositoriesByPattern(repos: T[], clonePattern: ClonePatternResult): T[]; //# sourceMappingURL=selection-strategy.d.ts.map