Module: Kontena::Cli::Stacks::Common::StackValuesFromOption

Included in:
BuildCommand, InstallCommand, UpgradeCommand, ValidateCommand
Defined in:
lib/kontena/cli/stacks/common.rb

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.included(where) ⇒ Object

Include to add –values-from option to read variable values from a YAML file and the -v variable=value option that can be used to pass variable values directly from command line



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/kontena/cli/stacks/common.rb', line 94

def self.included(where)
  where.prepend InstanceMethods

  where.option '--values-from', '[FILE]', 'Read variable values from a YAML file', multivalued: true do |filename|
    values_from_file.merge!(::YAML.safe_load(File.read(filename), [], [], true, filename))
    filename
  end

  where.option '--values-from-stack', '[STACK_NAME]', 'Read variable values from an installed stack', multivalued: true do |stackname|
    variables = read_values_from_stacks(stackname)
    Kontena.logger.debug { "Received variables from stack #{stackname} on Master: #{variables.inspect}" }
    warn "Stack #{stackname} does not have any values for variables" if variables.empty?
    values_from_installed_stacks.merge!(variables)
    stackname
  end

  where.option '-v', "VARIABLE=VALUE", "Set stack variable values, example: -v domain=example.com. Can be used multiple times.", multivalued: true, attribute_name: :var_option do |var_pair|
    var_name, var_value = var_pair.split('=', 2)
    values_from_value_options.merge!(::YAML.safe_load(::YAML.dump(var_name => var_value)))
    var_pair
  end
end