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

Add support for opt reference #6

Open
jadamon42 opened this issue Jul 2, 2020 · 1 comment
Open

Add support for opt reference #6

jadamon42 opened this issue Jul 2, 2020 · 1 comment

Comments

@jadamon42
Copy link

It would be really nice to add support for the opt reference, i.e.:
${opt:stage}

I think the only way to really do this would be to allow users to pass a cliOptions object to readYamlSync. Then you could treat it very similarly to the env reference.

Ideally, the following would be possible:

options: ${opt:}
.......
field: ${self:options.stage}

If the serverless file uses the opt reference, everything breaks, which is very unfortunate.

@jlitowitz
Copy link

jlitowitz commented Aug 31, 2020

I created PR #9 which should handle this, as I also came across this need. Along the way though, I found out you can work around this by passing in a context object into readYamlSync as follows. Just build up your desired opt values within the switch statement.

  return parser.readYamlSync(file,null,{
    opt: (x) => {
      switch(x[0]) {
        case 'stage':
          return 'dev';
        default:
          return x[1]; // expand upon this as necessary for your use case, ex:  x[1] || x[2] || x[3]
      }
    }
  });

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

2 participants