nitc :: CmdEntity :: init_mentity
If not already set, tries to find the mentity
from the mentity_name
.
This function try to match mentity_name
both as a full_name
and
name
.
Return states:
CmdSuccess
: everything was ok;ErrorMEntityNoName
: no mentity
and no mentity_name
provided;ErrorMEntityNotFound
: no mentity for mentity_name
;ErrorMEntityConflict
: mentity_name
was a non-qualified name that
returns more than one MEntity.
# Initialize the command mentity.
#
# If not already set, tries to find the `mentity` from the `mentity_name`.
#
# This function try to match `mentity_name` both as a `full_name` and
# `name`.
#
# Return states:
# * `CmdSuccess`: everything was ok;
# * `ErrorMEntityNoName`: no `mentity` and no `mentity_name` provided;
# * `ErrorMEntityNotFound`: no mentity for `mentity_name`;
# * `ErrorMEntityConflict`: `mentity_name` was a non-qualified name that
# returns more than one MEntity.
fun init_mentity: CmdMessage do
if mentity != null then
if mentity_name == null then mentity_name = mentity.as(not null).full_name
return new CmdSuccess
end
var mentity_name = self.mentity_name
if mentity_name == null or mentity_name.is_empty then return new ErrorMEntityNoName
mentity = model.mentity_by_full_name(mentity_name)
if mentity == null then
var mentities = model.mentities_by_name(mentity_name)
if mentities.is_empty then
var suggest = model.find(mentity_name, 3)
return new ErrorMEntityNotFound(mentity_name, suggest)
else if mentities.length > 1 then
return new ErrorMEntityConflict(mentity_name, mentities)
end
mentity = mentities.first
end
return new CmdSuccess
end
src/doc/commands/commands_base.nit:128,2--162,4