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

infer environment variable name similar to how variables names are inferred (ie from long form option) #117

Open
ebertech opened this issue Jan 21, 2022 · 1 comment

Comments

@ebertech
Copy link

Hi

Long time listener, first time caller.

I'm wondering if anyone is opposed to having the ability to have:

option %w{--beep-boop}, "VALUE", "the beep and the boop", :environment_variable => true

translate to

option %w{--beep-boop}, "VALUE", "the beep and the boop", :environment_variable => "BEEP_BOOP"

the algorithm for which would be taking doing

def environment_variable
  @environment_variable ||= attribute_name.upcase
end

plus allowing overrides via the traditional way as to not break existing stuff. This would be similar to how delegate is done in rails

https://apidock.com/rails/Module/delegate

Or if there's a smarter way to do this because I find myself either making a "Concern" that does this automagically or manually translating the name and upcasing it. Both of which seem...unrubyish.

I'm more than happy to provide code and tests and such, I was just making sure this hadn't been considered and discarded previously. In which case apologies for wasting your time.

@kigster
Copy link

kigster commented Sep 13, 2022

Not a bad idea, minus hard-coding of the naming convention converter: the conversion from an option name to ENV variable should be extensible by a class, for example:

option %w{--beep-boop}, "VALUE", "the beep and the boop", :env_mapper => EnvironmentMapper.new
class EnvironmentMapper
   def call(value)
      "FOO_#{value.to_s.upcase}"
   end
end

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