postmark-cli icon indicating copy to clipboard operation
postmark-cli copied to clipboard

Allow removing a template using the CLI

Open alicenstar opened this issue 1 year ago • 5 comments

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.

alicenstar avatar Aug 10 '23 15:08 alicenstar

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

tomek-ac avatar Aug 17 '23 20:08 tomek-ac

@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 avatar Sep 22 '23 15:09 alicenstar

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.

alicenstar avatar Sep 22 '23 16:09 alicenstar

@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.

rlueder avatar Sep 30 '23 06:09 rlueder

@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?

tomek-ac avatar Oct 02 '23 17:10 tomek-ac