nitc :: CmdEntity :: defaultinit
# A command about a MEntity
class CmdEntity
super DocCommand
# MEntity this command is about
#
# Alternatively you can provide a `mentity_name`.
var mentity: nullable MEntity = null is optional, writable
# Name of the mentity this command is about
#
# Alternatively you can directly provide the `mentity`.
var mentity_name: nullable String = null is optional, writable
# 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
# See `init_mentity`.
redef fun init_command do return init_mentity
end
src/doc/commands/commands_base.nit:114,1--166,3