sinofseven / serverless-s3-remover

this is plugin of serverless, before "sls remove", this empties the s3 bucket.
MIT License
39 stars 11 forks source link

Populating the configuration object before using it #10

Closed chechu closed 6 years ago

chechu commented 6 years ago

Thank you for your usefull and awesome work!

Proposal With this PR it'll be allowed to define the variable "prompt" in a dynamic way, taking advantage of the population of variables mechanism offered by Serverless.

Until now, prompt accepts true or false as valid values. With this PR, it'll be allowed definitions as the next ones:

custom:
  boolean:
    true: true
    false: false
  remover:
    prompt: ${self:custom.boolean.${opt:s3-remover-prompt, 'true'}}

The new code will be able to expand expressions like ${self:custom.boolean.${opt:s3-remover-prompt, 'true'}}, getting at the end the literal value. With the previous version of the code, this expression wasn't expanded, and it was always evaluated as true (because it was a non empty string).

Motivation I use the previous expression to set a value to the prompt variable to enable or disable the prompt feature from the command line. I usually enable the prompt feature, but for integration tests, where I want to deploy and remove services automatically, I prefer to disable it. With my changeset, I can use the command line argument --s3-remover-prompt false to disable the prompt feature.

Minor change This changeset is 100% compatible with the previous uses of the plugin. It doesn't break anything at all.

Hope you decide to merge this changeset in the master branch of the main repository, and release a new version of the npm package. I will appreciate it a lot. Don't hesitate to contact me if I can do something more.

sinofseven commented 6 years ago

Thank you, your PR!

I'll merge.