nitc :: CmdComment :: defaultinit
# Retrieve the MDoc related to a MEntity
class CmdComment
super CmdEntity
# Allow fallback
#
# If `true`, the command uses `mdoc_or_fallback`.
# Default is `true`.
var fallback = true is optional, writable
# Retrieve the full documentation
#
# If `true`, retrieves the full documentation.
# If `false`, retrieves only the synopsis.
# Default is `true`.
#
# Since the rendering the final string (md, html...) depends on the kind of
# client, the handling of this option is delegated to submodules.
var full_doc = true is optional, writable
# Format to render the comment
#
# Can be one of `raw`, `html` or `md`.
# Default is `raw`.
var format = "raw" is optional, writable
# MDoc to return
var mdoc: nullable MDoc = null is optional, writable
# Same states than `CmdEntity::init_mentity`
#
# Plus returns `WarningNoMDoc` if no MDoc was found for the MEntity.
redef fun init_command do
var res = super
if not res isa CmdSuccess then return res
var mentity = self.mentity.as(not null)
if mdoc == null then
mdoc = if fallback then mentity.mdoc_or_fallback else mentity.mdoc
end
if mdoc == null then return new WarningNoMDoc(mentity)
return res
end
# Render `mdoc` depending on `full_doc` and `format`
fun render_comment: nullable Writable do
var mdoc = self.mdoc
if mdoc == null then return null
if full_doc then return mdoc.documentation
return mdoc.synopsis
end
end
src/doc/commands/commands_model.nit:23,1--75,3