Sha256: 0c0c6ac2db28753375d7871c18c7ae21f713c807ef73cfcb1b35efe4ba882771

Contents?: true

Size: 1.26 KB

Versions: 24

Compression:

Stored size: 1.26 KB

Contents

require "English"

module Dotenv
  module Substitutions
    # Substitute shell commands in a value.
    #
    #   SHA=$(git rev-parse HEAD)
    #
    module Command
      class << self
        INTERPOLATED_SHELL_COMMAND = /
          (?<backslash>\\)?   # is it escaped with a backslash?
          \$                  # literal $
          (?<cmd>             # collect command content for eval
            \(                # require opening paren
            ([^()]|\g<cmd>)+  # allow any number of non-parens, or balanced
                              # parens (by nesting the <cmd> expression
                              # recursively)
            \)                # require closing paren
          )
        /x

        def call(value, _env, _is_load)
          # Process interpolated shell commands
          value.gsub(INTERPOLATED_SHELL_COMMAND) do |*|
            # Eliminate opening and closing parentheses
            command = $LAST_MATCH_INFO[:cmd][1..-2]

            if $LAST_MATCH_INFO[:backslash]
              # Command is escaped, don't replace it.
              $LAST_MATCH_INFO[0][1..-1]
            else
              # Execute the command and return the value
              `#{command}`.chomp
            end
          end
        end
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 5 rubygems

Version Path
avalara_sdk-24.12.2 vendor/bundle/ruby/2.7.0/gems/dotenv-2.7.6/lib/dotenv/substitutions/command.rb
avalara_sdk-24.12.1 vendor/bundle/ruby/2.7.0/gems/dotenv-2.7.6/lib/dotenv/substitutions/command.rb
avalara_sdk-24.12.0 vendor/bundle/ruby/2.7.0/gems/dotenv-2.7.6/lib/dotenv/substitutions/command.rb
avalara_sdk-24.2.29 vendor/bundle/ruby/2.7.0/gems/dotenv-2.7.6/lib/dotenv/substitutions/command.rb
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/dotenv-2.7.6/lib/dotenv/substitutions/command.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/dotenv-2.7.6/lib/dotenv/substitutions/command.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/dotenv-2.7.6/lib/dotenv/substitutions/command.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/dotenv-2.7.6/lib/dotenv/substitutions/command.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/dotenv-2.7.6/lib/dotenv/substitutions/command.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/dotenv-2.7.6/lib/dotenv/substitutions/command.rb
dotenv-2.7.6 lib/dotenv/substitutions/command.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/dotenv-2.7.0/lib/dotenv/substitutions/command.rb
chatops-rpc-0.0.2 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/dotenv-2.7.5/lib/dotenv/substitutions/command.rb
chatops-rpc-0.0.1 fixtures/chatops-controller-example/vendor/bundle/ruby/2.5.0/gems/dotenv-2.7.5/lib/dotenv/substitutions/command.rb
dotenv-2.7.5 lib/dotenv/substitutions/command.rb
dotenv-2.7.4 lib/dotenv/substitutions/command.rb
dotenv-2.7.3 lib/dotenv/substitutions/command.rb
dotenv-2.7.2 lib/dotenv/substitutions/command.rb
dotenv-2.7.1 lib/dotenv/substitutions/command.rb
dotenv-2.7.0 lib/dotenv/substitutions/command.rb