lib/awskeyring_command.rb in awskeyring-1.4.0 vs lib/awskeyring_command.rb in awskeyring-1.5.0
- old
+ new
@@ -158,18 +158,20 @@
end
end
desc 'exec ACCOUNT command...', I18n.t('exec.desc')
method_option 'no-token', type: :boolean, aliases: '-n', desc: I18n.t('method_option.notoken'), default: false
+ method_option 'no-bundle', type: :boolean, aliases: '-b', desc: I18n.t('method_option.nobundle'), default: false
# execute an external command with env set
def exec(account, *command)
if command.empty?
warn I18n.t('message.exec')
exit 1
end
cred = age_check_and_get(account: account, no_token: options['no-token'])
env_vars = Awskeyring::Awsapi.get_env_array(cred)
+ unbundle if options['no-bundle']
begin
pid = Process.spawn(env_vars, command.join(' '))
Process.wait pid
$CHILD_STATUS
rescue Errno::ENOENT => e
@@ -542,8 +544,21 @@
Thor::LineEditor.readline((message + ' (optional)').rjust(20) + ': ')
elsif limited_to
Thor::LineEditor.readline(message.rjust(20) + ': ', limited_to: limited_to)
else
Thor::LineEditor.readline(message.rjust(20) + ': ')
+ end
+ end
+
+ def unbundle
+ to_delete = ENV.keys.select { |elem| elem.start_with?('BUNDLER_ORIG_') }
+ bundled_env = to_delete.map { |elem| elem[('BUNDLER_ORIG_'.length)..-1] }
+ to_delete << 'BUNDLE_GEMFILE'
+ bundled_env.each do |env_name|
+ ENV[env_name] = ENV['BUNDLER_ORIG_' + env_name]
+ to_delete << env_name if ENV['BUNDLER_ORIG_' + env_name].start_with? 'BUNDLER_'
+ end
+ to_delete.each do |env_name|
+ ENV.delete(env_name)
end
end
end