ActiveCampaign / postmark-cli

The official CLI tool for Postmark
https://postmarkapp.com
MIT License
79 stars 9 forks source link

Allow removing a template using the CLI #75

Open alicenstar opened 1 year ago

alicenstar commented 1 year ago

I'd like for there to be a way to delete templates using the CLI. We are managing our templates using a GitHub repository, and this poses some difficulty in maintaining the templates long term.

tomek-ac commented 1 year ago

@alicenstar can you give us some more context? How would you like this to work?

alicenstar commented 1 year ago

@tomek-ac I'm flexible in implementation but it'd be nice to be able to do something like postmark template -d template-name. Or adding this functionality to the API would be helpful as well.

alicenstar commented 1 year ago

My team was trying to set up a way to manage postmark templates in a repository using GitHub Actions and the Postmark CLI, but the only case we can't handle is if we want to delete a template.

rlueder commented 1 year ago

@alicenstar I opened a PR here which includes a basic delete command, keep in mind it'll delete ALL templates as that's what I currently need for my use case but should be easy enough to tweak and allow deleting a single template by id/alias or a list of templates.

I was having too much fun with this one and improved the UX by allowing users to select whether they want to delete by id (one or multiple) or delete all templates. :)

Also added some extra check for delete all as it can be quite destructive.

The underlying Postmark client already included a deleteTemplate method so it was easy enough to expose to the CLI.

To use it locally run:

$ npm run build

then

$ ./dist/index.js templates delete

> ./dist/index.js templates delete
? Please enter your server token ••••••••••••••••••••••••••••••••••••
? Choose how you want to delete templates: Delete templates by id
? Enter template id(s) - separated by commas if multiple: 33336536, 33336535, 33336549
All finished! 3 templates have been deleted.
> ./dist/index.js templates delete
? Please enter your server token ••••••••••••••••••••••••••••••••••••
? Choose how you want to delete templates: Delete all templates
? Which template type do you want to delete? Templates
? Delete ALL templates? Are you sure? yes
? Enter "delete all templates" to confirm: delete all templates
All finished! 80 templates have been deleted.
tomek-ac commented 1 year ago

@rlueder thanks for working on this!

@alicenstar what do you think? Would this work in your case? The proposed implementation seems to require providing the parameters interactively so it will probably not work in a hands-free GH action?