Function resolveCommand

  • Resolves a command based on the provided command string and directory path, returning the first matching command.

    This function attempts to locate a matching command file for the provided command string. If found, it imports and returns the associated command. If a command file isn't directly found, it checks if the path is a directory and treats it as a pass-through command, allowing deeper command resolution.

    If neither a command file nor a directory is found, it checks for parameterized command files (e.g., [param].ts or [...param].ts) in the expected directory and tries to resolve them.

    The function provides detailed error feedback if the command can't be resolved or if the found module doesn't export a default command.

    Parameters

    Returns Promise<ResolvedCommand>

    Object containing details about the resolved command, the path to the command file, any parameters, and a function to resolve the next command, if any.

    Throws an error if command resolution fails due to missing tokens, command not found, or missing default export.