Aad Mathijssen
Aad Mathijssen

Reputation: 650

Use Composer CLI to add data to the extra property

According to the documentation of the extra property of the composer.json schema, allows setting of "arbitrary extra data for consumption by scripts."

For scripting purposes, it would be nice if data can be added to the extra property via the command-line. It have tried composer config extra.foo bar, but this gives the error Setting extra.foo does not exist or is not supported by this command.

So I was wondering: is there a way to use the Composer CLI to add data to the extra property?

UPDATE: Composer 1.1.0 has added supported for this feature: https://getcomposer.org/doc/03-cli.md#modifying-extra-values Unfortunately, it is not possible to add boolean or numeric values, as each value is added as a string. See also issue #5492 of the Composer project.

Upvotes: 5

Views: 2516

Answers (2)

Aad Mathijssen
Aad Mathijssen

Reputation: 650

As of Composer 1.1.0, it is is possible to add string values to the extra property using the CLI:

composer config extra.foo "some text"
composer config extra.bar 123
composer config extra.baz true

This results in the following:

"extra": {
    "foo": "some text",
    "bar": "123",
    "baz": "true"
}

As of Composer 2.0, it is possible to add values in any JSON value type using the --json and --merge flags. This includes the possibility to add numbers and booleans:

composer config --json extra.foo '"some text"'
composer config --json extra.bar 123
composer config --json extra.baz true

This results in the following:

"extra": {
    "foo": "some text",
    "bar": 123,
    "baz": true
}

The documentation of this feature shows how you can add a JSON object from the CLI.

Upvotes: 6

Sven
Sven

Reputation: 70883

There is no way, and the reason is that this usually is bound to some very specific local use case that does not apply to the general audience.

All parameters that can be influenced with composer config are listed here: https://getcomposer.org/doc/06-config.md

If you want to add data to the "extra" part, you have to edit it by hand or let your script do it in some other way.

Upvotes: 0

Related Questions