Commit f9c8ebad authored by Laurent Briais's avatar Laurent Briais

Fix for properties specified on command line representing a reference to another entity

If no entity is found no error is actually raised. Nevertheless an error will be raised if the entity becomes therefore invalid.
parent e6e8088f
......@@ -17,8 +17,17 @@ module PowerStencil
unless config[:property].nil?
config[:property].each do |property_def|
if md = property_def.match(/^\s*(?<prop_name>[^:=]+)\s*[:=]\s*(?<prop_val>.*)\s*$/)
logger.debug "Using extra properties from command line '#{md['prop_name']}' = '#{md['prop_val']}'"
entity_as_hash[md['prop_name'].to_sym] = md['prop_val']
property_value = md['prop_val']
logger.debug "Using extra properties from command line '#{md['prop_name']}' = '#{property_value}'"
if pmd = property_value.match(/^\s*!entity\s+(?<entity_type>[^\/]+)\/(?<entity_name>.*)\s*$/)
type = pmd['entity_type'].to_sym
name = pmd['entity_name']
referenced_entity = project.engine.entity(type, name)
property_value = referenced_entity.to_reference unless referenced_entity.nil?
puts_and_logs "Could not find entity '#{type.to_s}/#{name}' !", logs_as: :error, check_verbose: false if referenced_entity.nil?
end
entity_as_hash[md['prop_name'].to_sym] = property_value
else
raise PowerStencil::Error, "Invalid command line property definition: '#{property_def}'"
end
......@@ -35,6 +44,8 @@ module PowerStencil
new_entity = edit_before_save new_entity
end
new_entity.resolve_fields_references!
new_entity.valid? raise_error: true
project.track_action_with_git("Created '#{new_entity.as_path}' (and potential dependencies).") do
new_entity.save
......@@ -63,7 +74,6 @@ module PowerStencil
modifications_valid? modified_path, entity
end
project.engine.root_universe.replace entity, modified_entity
modified_entity.resolve_fields_references!
modified_entity
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment