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
Allow custom CLI commands to be added by extensions #7675
Conversation
@nickrum Thoughts on this vs cli commands as an extension type? It's a strange mix 🤔 Theoretically, you could do custom endpoints through a custom hook as well by attaching to the app init hook. Maybe custom endpoints should just be another hook? Food for thought! |
@rijkvanzanten I'd rather have it as a separate extension type. Right now, hooks are only meant for one-off actions at certain points within the lifecycle of Directus or to alter data-flow at certain user-triggered events. If we start to allow adding "additional functionality" through hooks, this breaks separation of concerns. It makes it much harder to reason, where new features are coming from. Also, IMO the CLI integrated into the API is only meant for the bare minimum of commands necessary to make the Directus API usable. I'm not sure, if we should even support extending it at all. |
IMO there's lots of valid reasons for extending the CLI. Some of my current use cases are;
Currently I'm just using a separate commander instance and importing the Directus API (eg, database, services, etc). This works, but it does have some disadvantages;
Also, I think having the ability to add REST API endpoints using hooks is important too. Some situations where I'm currently using the
|
An alternative to adding CLI hooks could be to export the commander program in a way that it can be imported and extended. For example;
|
I agree, but I see that as 100% user-risk. We don't actively recommend nor demonstrate that way of injecting custom logic, but it's a very nice escape hatch to have for power users that know what they're doing (as demonstrated by @smilledge). I'm down with this addition 👍🏻 One point of concern you brought up earlier today @nickrum is the fact that this change requires the extensions to be initialized even though its only for the single CLI invocation. Is that a technical problem, or just something we need to take into account moving forwards? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
With the recent changes to endpoints, you should be able to do this with a custom endpoint as well.
Just something to take into account, especially concerning the upcoming changes that are necessary for OTA installation. |
Fixes a regression introduced in #7675
Fixes a regression introduced in #7675
Fixes a regression introduced in #7675
Fixes a regression introduced in #7675
* Fix typescript errors in shared package * Hooks for adding custom CLI commands * Add CLI hooks to documentation
PR #7675 was intended to run hooks when using the users/roles command in the CLI. Using extensions everywhere can cause major issues, as the database may or may not exist, and may or may not be up to date.
✨️ Improvements
🐛 Bugfixes
user.create.before
). However, I think this should be the expected behaviour?