Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI command for adding patches #81

Closed
danepowell opened this issue Oct 25, 2016 · 16 comments
Closed

CLI command for adding patches #81

danepowell opened this issue Oct 25, 2016 · 16 comments

Comments

@danepowell
Copy link
Collaborator

danepowell commented Oct 25, 2016

In the same way that Composer includes a "require" command, so that you can run composer require cweagans/composer-patches instead of editing composer.json to insert the dependency, it would be really nice if composer-patches provided a way to patch packages from the command line.

I could see this either taking the form of a patch command, or an additional patch parameter to the require command (if Composer lets you modify built-in commands... not sure).

@danepowell
Copy link
Collaborator Author

For anyone looking for a workaround, I can't really find one. I was hoping composer config would work but it doesn't allow setting an array below three levels deep. So you can't add a new patch without deleting all of the existing ones.

@weitzman
Copy link

I would really use this as well. And thanks @danepowell for saying that the workaround I had in mind doesn't work either. Have you found anything besides loading combo.json and writing it back to disk? Ping @grasmash as well.

@grasmash
Copy link
Contributor

grasmash commented Mar 23, 2017

This package could provide a static method that would read the composer.json file, modify, and write it to disk. That method can then be placed in a script in your composer.json:

  "scripts": {
    "add-patch": "Cweagens\\ComposerPatches\\Plugin::add-patch"
  }

Allowing you to call composer add-patch [patch.patch].

@cweagans
Copy link
Owner

Plugins can provide commands, I think. No need to define a separate script in your composer.json.

@alisonjo315
Copy link

Yes: https://getcomposer.org/doc/articles/plugins.md#command-provider

And I see references to command-y things here...
https://github.com/cweagans/composer-patches/blob/master/src/Patches.php#L354

But I definitely don't understand how I'm meant to use it/them!

@cweagans
Copy link
Owner

cweagans commented Apr 20, 2017

The steps are basically as follows:

  • Implement Composer\Plugin\Capability\CommandProvider in cweagans\Composer\Patches - this should return an array of Command objects.
  • Create a new class that extends Composer\Command\BaseCommand. configure() should set the name of the command (i.e. patch-add or whatever - see example you linked for the exact syntax) and execute() should actually do the work of loading composer.json (or the configured patches file) and adding the patch.

If you start working on this and get stuck, push your code somewhere and let me know. Happy to help as needed.

@geek-merlin
Copy link

I think this is a very useful case of a generic CLI json modifier. I remember there was a drupal-console generic yaml modifyer.

Would really love to see both (the generic one and the patches one, maybe just depending).

@grasmash
Copy link
Contributor

grasmash commented Mar 7, 2018

https://stedolan.github.io/jq/
https://github.com/grasmash/yaml-cli

@cweagans
Copy link
Owner

cweagans commented Jun 2, 2018

This is on the roadmap for 2.0.0 (see #93)

@cweagans cweagans mentioned this issue Jun 2, 2018
36 tasks
@szeidler
Copy link

Nice to see, that the CLI is on the Roadmap for 2.x.

Recently I started an initial composer patches CLI plugin for the 1.x branch at https://github.com/szeidler/composer-patches-cli , to test a bit, what is possible and what not.

We used it for adding the recent Drupalgeddon security patches in an automated way.

@cweagans
Copy link
Owner

I saw that. :) I'll probably end up using a fair amount of your code -- there's a lot of good stuff there.

@geek-merlin
Copy link

Note: The mentioned szeidler/composer-patches-cli only works for adding patches via extra/patches-file. It does not work for patches added via extra/patches.

@christopher-hopper
Copy link

christopher-hopper commented Mar 6, 2019

Would it be possible, as part of this, to allow for optional metadata to be stored with a patch. If we could work out how to allow for optional extra metadata with a patch, that'd be great. Currently we only have a single key-value for a each patch.

If the patch storage JSON structure could accommodate more, optionally, we do...

...Thinking like:

This would be helpful so that add-ons / plug-ins could be written to support management of patches by calling issue queue apis, to check on the status of an issue associated with a patch.

Would be happy to track this separately as a Nice to Have, or somewhere else on the roadmap.

@frederickjh
Copy link

@christopher-hopper, @cweagans stated above that he was planning to use a lot of @szeidler's code from szeidler/composer-patches-cli. This repository includes the functionality that you are asking for.

@cweagans
Copy link
Owner

cweagans commented Mar 6, 2019

@christopher-hopper Please open an issue for that. I'm not opposed to adding additional optional metadata fields for Patch objects in the 2.x releases.

@cweagans
Copy link
Owner

cweagans commented Feb 7, 2023

I've made a note to handle this in main.

@cweagans cweagans closed this as completed Feb 7, 2023
@cweagans cweagans mentioned this issue Feb 7, 2023
31 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants