class Terraspace::CLI::New::Hook
Public Class Methods
options()
click to toggle source
# File lib/terraspace/cli/new/hook.rb, line 7 def self.options [ [:force, aliases: %w[y], type: :boolean, desc: "Bypass overwrite are you sure prompt for existing files"], [:kind, default: "terraform", desc: "terraform or terraspace"], [:name, desc: "Command name. Defaults to apply for terraform kind and build for terraspace kind"], [:type, default: "project", desc: "project, stack or module"], ] end
source_root()
click to toggle source
# File lib/terraspace/cli/new/hook.rb, line 17 def self.source_root File.expand_path("../../../templates/base/hook", __dir__) end
Public Instance Methods
check_stack_arg()
click to toggle source
# File lib/terraspace/cli/new/hook.rb, line 54 def check_stack_arg return if type == "project" return unless stack.nil? # Else check for STACK argument for type module or stack puts <<~EOL Required STACK argument, either the module or stack name. Usage: terraspace new hook STACK --type #{type} EOL exit 1 end
create()
click to toggle source
# File lib/terraspace/cli/new/hook.rb, line 66 def create directory ".", dest end
Private Instance Methods
dest()
click to toggle source
# File lib/terraspace/cli/new/hook.rb, line 39 def dest map = { project: "config/hooks", stack: "app/stacks/#{stack}/config/hooks", module: "app/modules/#{stack}/config/hooks", } map[type.to_sym] end
hook_path()
click to toggle source
# File lib/terraspace/cli/new/hook.rb, line 48 def hook_path "#{dest}/#{kind}.rb" end
kind()
click to toggle source
# File lib/terraspace/cli/new/hook.rb, line 22 def kind valid_kinds = %w[terraform terraspace] kind = @options[:kind] valid_kinds.include?(kind) ? kind : "terraform" # fallback to terraform if user provides invalid type end
name()
click to toggle source
# File lib/terraspace/cli/new/hook.rb, line 34 def name return options[:name] if options[:name] kind == "terraform" ? "apply" : "build" end
type()
click to toggle source
# File lib/terraspace/cli/new/hook.rb, line 28 def type valid_types = %w[project stack module] type = @options[:type] valid_types.include?(type) ? type : "project" # fallback to project if user provides invalid type end