Skip to content

UnstructuredData does not apply --field option #1171

@ilyaukin

Description

@ilyaukin

Steps to reproduce

I have a command which returns UnstucturedData, something like

public function myCommand()
{
    return  new UnstructuredData(['id' => '123',....]);
}

Then I run robo my:command --field=id and I expect that I get exact id as string.

Expected behavior

I expect output 123.

Actual behavior

I see the error

 [error]  The format string cannot be used with the data produced by this command, which was an instance of Consolidation\OutputFormatters\StructuredData\UnstructuredData.  Valid formats are: csv,json,list,null,php,print-r,tsv,var_export,xml,yaml 

If I comment out these lines in FormatterManager.php

        if (!is_string($structuredOutput) && !$this->isValidFormat($formatter, $structuredOutput)) {
            $validFormats = $this->validFormats($structuredOutput);
            throw new InvalidFormatException((string)$format, $structuredOutput, $validFormats);
        }

I see the correct result...

System Configuration

OS: Debian GNU/Linux 12 (bookworm)
PHP 8.3.10
Robo 4.0.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions