nitc :: CmdMains :: defaultinit
# Cmd that finds the mains of an `mentity`
class CmdMains
super CmdEntityList
redef fun init_results do
if results != null then return new CmdSuccess
var res = super
if not res isa CmdSuccess then return res
var mentity = self.mentity.as(not null)
var mentities = new Array[MEntity]
if mentity isa MPackage then
for mmodule in mentity.collect_all_mmodules(filter) do
if mmodule_has_main(mmodule) then mentities.add mmodule
end
else if mentity isa MGroup then
for mmodule in mentity.collect_all_mmodules(filter) do
if mmodule_has_main(mmodule) then mentities.add mmodule
end
else if mentity isa MModule then
if mmodule_has_main(mentity) then mentities.add mentity
else
return new WarningNoMains(mentity)
end
if mentities.is_empty then return new WarningNoMains(mentity)
self.results = mentities
return res
end
# Does `mmodule` has a `main` method?
private fun mmodule_has_main(mmodule: MModule): Bool do
for mclassdef in mmodule.collect_redef_mclassdefs(filter) do
if mclassdef.name != "Sys" then continue
for mpropdef in mclassdef.collect_redef_mpropdefs(filter) do
if mpropdef.name == "main" then return true
end
end
return false
end
end
src/doc/commands/commands_main.nit:19,1--61,3