0

How can I add a package to the replace section of composer.json using cli?

For example composer require vendor/package adds a package to the require section.

In composer docs, I did not find anything like composer replace vendor/package command.

yivi
  • 42,438
  • 18
  • 116
  • 138
Victor S.
  • 2,510
  • 3
  • 22
  • 35
  • If the documentation does not mention this, why not simply open the file and edit it by hand? – Nico Haase Nov 19 '21 at 08:30
  • when necessary, I edit the file `composer.json`. But I am looking for an elegant solution. Preferably out of the box. I need this for the same reason the `composer require` exists. It is more convenient, simpler, there is no need to check for duplication and so on. – Victor S. Nov 19 '21 at 11:06

1 Answers1

2

Editing the replace section of composer.json is not currently supported via the CLI.

Neither editing conflict, for that matter.

The complete list of CLI options is listed here.

You could use something like jq to do it if for some reason you need to do it programmatically via the CLI (e.g.), but more often than not is the kind of thing a developer adds manually to their composer.json when needed.

yivi
  • 42,438
  • 18
  • 116
  • 138
  • thanks for the answer, in general I agree with you, but maybe there will still be an elegant solution via the CLI or the question will attract the attention of composer developers. – Victor S. Nov 24 '21 at 19:15