Does terraspace boot hook have access to know what command is being run?

Hi there – as discussed in this topic custom layering support, I needed to create a boot hook which will look for certain env variables and then set the AWS credentials I need for the terraspace build phase.

However, I happen to run terraspace new hook without any of those env variables set and so my boot.rb hook hit an exception.

Is there any ruby code I can reference which will give me access to the arguments passed to terraspace so that I might restrict running my custom code only when a command involving the build phase is called?

Thanks.

Think ARGV can help. This is a pure ruby method that returns the original cli args. So something like this:

config/boot.rb

return unless %w[build up down all].include?(ARGV[0])
# rest of my boot logic

Or check for the new command specifically:

config/boot.rb

return if ARGV[0] == "new"
# rest of my boot logic

You can also be a little more heavy handed and wrap the boot hook with a begin ... rescue

config/boot.rb

begin
  # my boot code
rescue Exception
  puts "WARN: config/boot.rb errored"
end

The ARGV approach seems a little better for this case.