nitc :: Nitx :: defaultinit
# Nitx handles console queries
#
# Using `prompt`, the command line can be turned on an interactive tool.
class Nitx
# Model that contains the informations to display
var model: Model
# Mainmodule for class linearization
var mainmodule: MModule
# ModelBuilder to access AST nodes
var modelbuilder: ModelBuilder
# Catalog if any
var catalog: nullable Catalog = null is optional
# Do not use colors in the output
var no_color = false is optional
# Displays the welcome message and start prompt.
fun start do
welcome
prompt
end
# Displays the welcome message and the list of loaded modules.
fun welcome do
print "Welcome in the Nit Index!"
print ""
print "Loaded packages:\n"
var cmd = new CmdModelEntities(model, kind = "packages")
cmd.init_command
for mpackage in cmd.results.as(not null) do
print " * {mpackage.full_name}"
end
help
end
# Displays the list of available queries.
fun help do
# TODO automatize that
print "\nCommands:\n"
for usage, doc in parser.commands_usage do
var l = usage.length / 8
print "\t{usage}{"\t" * (3 - l)}{doc}"
end
print "\n"
print "\t:h\t\t\tdisplay this help message"
print "\t:q\t\t\tquit interactive mode"
print ""
end
# Prompts the user for a query.
fun prompt do
var line = sys.prompt(">> ", true)
if line != null then
do_command(line)
else
# EOF
exit 0
end
prompt
end
# Parser used to process doc commands
var parser = new CommandParser(model, mainmodule, modelbuilder, catalog) is lazy
# Processes the query string and performs it.
fun do_command(str: String) do
if str == ":q" then
exit 0
else if str == ":h" then
help
return
end
parser.execute(str, no_color)
end
end
src/nitx.nit:41,1--119,3