/*
 * Copyright 2026, Jaime Terrats.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
import { Flags } from '@salesforce/sf-plugins-core';
export const workspaceFlags = {
    'target-dir': Flags.directory({
        summary: 'Workspace root to target (defaults to cwd).',
        description: 'Explicit workspace directory for state writes. When omitted, uses the current working directory.',
        exists: true,
    }),
};
export const taskIdentifierFlags = {
    ...workspaceFlags,
    task: Flags.string({
        char: 't',
        summary: 'Task id.',
        description: 'Id of the task. Alias: --id.',
    }),
    id: Flags.string({
        summary: 'Task id.',
        description: 'Id of the task. Alias: --task.',
    }),
};
export function resolveTaskId(flags) {
    const taskId = flags.task ?? flags.id;
    if (!taskId)
        throw new Error('Either --task or --id is required.');
    return taskId;
}
export function splitCsv(value) {
    if (!value)
        return [];
    const results = [];
    let current = '';
    let inQuotes = false;
    let quoteChar = '';
    for (const ch of value) {
        if (!inQuotes && (ch === '"' || ch === "'")) {
            inQuotes = true;
            quoteChar = ch;
        }
        else if (inQuotes && ch === quoteChar) {
            inQuotes = false;
            quoteChar = '';
        }
        else if (!inQuotes && ch === ',') {
            const trimmed = current.trim();
            if (trimmed)
                results.push(trimmed);
            current = '';
        }
        else {
            current += ch;
        }
    }
    const trimmed = current.trim();
    if (trimmed)
        results.push(trimmed);
    return results;
}
//# sourceMappingURL=task-flags.js.map