// SPDX-License-Identifier: Apache-2.0
import { Flags as flags } from './flags.js';
import { ArgumentProcessor } from '../argument-processor.js';
/**
 * Helper function to convert a flag object to CLI option string
 * @param flag - The command flag
 * @returns CLI option string (e.g., '--deployment')
 */
export function optionFromFlag(flag) {
    return `--${flag.name}`;
}
/**
 * Helper function to create base argv array for command execution
 * @returns Base argv array
 */
export function newArgv() {
    return ['${PATH}/node', '${SOLO_ROOT}/solo.ts'];
}
/**
 * Helper function to append global flags to argv
 * @param argv - The argument array to append to
 * @param cacheDirectory - Optional cache directory path
 * @returns Updated argv array
 */
export function argvPushGlobalFlags(argv, cacheDirectory = '') {
    argv.push(optionFromFlag(flags.devMode), optionFromFlag(flags.quiet));
    if (cacheDirectory) {
        argv.push(optionFromFlag(flags.cacheDir), cacheDirectory);
    }
    return argv;
}
/**
 * Helper function to invoke a Solo command with proper task integration
 * @param title - Task title to display
 * @param commandName - Command name for task tracking
 * @param callback - Function that returns the argv array
 * @param taskList - TaskList instance for managing parent-child task relationships
 * @param skipCallback - Optional function to determine if task should be skipped
 * @returns Task object for Listr
 */
export function invokeSoloCommand(title, commandName, callback, taskList, skipCallback) {
    return {
        title,
        skip: skipCallback || (() => false),
        task: async (_, taskListWrapper) => {
            return subTaskSoloCommand(commandName, taskListWrapper, callback, taskList);
        },
    };
}
/**
 * Helper function to execute a Solo command and return child tasks
 * @param commandName - Command name for task tracking
 * @param taskListWrapper - Task list wrapper from Listr
 * @param callback - Function that returns the argv array
 * @param taskList - TaskList instance for managing parent-child task relationships
 * @returns Child tasks from command execution
 */
export async function subTaskSoloCommand(commandName, taskListWrapper, callback, taskList) {
    taskList.parentTaskListMap.set(commandName, { taskListWrapper });
    const newArgv = callback();
    await ArgumentProcessor.process(newArgv);
    return taskList.parentTaskListMap.get(commandName).children;
}
//# sourceMappingURL=command-helpers.js.map