Initialize commands from HTTP requests

FIXME: this module is pretty tied up to the nitwed routes.

To be more generic, param names should be extracted as variables.

Redefined classes

redef class CmdAncestors

nitc :: commands_http $ CmdAncestors

MEntity ancestors command
redef class CmdCatalogPerson

nitc :: commands_http $ CmdCatalogPerson

Retrieve a person from the catalog
redef class CmdCatalogTag

nitc :: commands_http $ CmdCatalogTag

Retrieve the packages for a tag
redef abstract class CmdCode

nitc :: commands_http $ CmdCode

Abstract command that returns source-code pieces
redef class CmdComment

nitc :: commands_http $ CmdComment

Retrieve the MDoc related to a MEntity
redef class CmdDescendants

nitc :: commands_http $ CmdDescendants

MEntity descendants command
redef class CmdEntity

nitc :: commands_http $ CmdEntity

A command about a MEntity
redef class CmdEntityCode

nitc :: commands_http $ CmdEntityCode

Cmd that finds the source code related to an mentity
redef abstract class CmdEntityList

nitc :: commands_http $ CmdEntityList

A command about a MEntity that returns a list of mentities
redef abstract class CmdError

nitc :: commands_http $ CmdError

Command Error
redef abstract class CmdGraph

nitc :: commands_http $ CmdGraph

An abstract command that returns a dot graph
redef class CmdInheritanceGraph

nitc :: commands_http $ CmdInheritanceGraph

Render a hierarchy graph for mentity if any.
redef abstract class CmdList

nitc :: commands_http $ CmdList

A command that returns a list of results
redef abstract class CmdMessage

nitc :: commands_http $ CmdMessage

Command message
redef class CmdModelEntities

nitc :: commands_http $ CmdModelEntities

A command that returns a list of all mentities in a model
redef class CmdSearch

nitc :: commands_http $ CmdSearch

A free text search command
redef abstract class CmdWarning

nitc :: commands_http $ CmdWarning

Command Warning
redef abstract class DocCommand

nitc :: commands_http $ DocCommand

Documentation command
redef class ErrorMEntityConflict

nitc :: commands_http $ ErrorMEntityConflict

Multiple MEntities matching mentity_name
redef class ErrorMEntityNoName

nitc :: commands_http $ ErrorMEntityNoName

No MEntity name provided
redef class ErrorMEntityNotFound

nitc :: commands_http $ ErrorMEntityNotFound

No MEntity matching mentity_name
redef class HttpRequest

nitc :: commands_http $ HttpRequest

A request received over HTTP, is build by HttpRequestParser

All class definitions

redef class CmdAncestors

nitc :: commands_http $ CmdAncestors

MEntity ancestors command
redef class CmdCatalogPerson

nitc :: commands_http $ CmdCatalogPerson

Retrieve a person from the catalog
redef class CmdCatalogTag

nitc :: commands_http $ CmdCatalogTag

Retrieve the packages for a tag
redef abstract class CmdCode

nitc :: commands_http $ CmdCode

Abstract command that returns source-code pieces
redef class CmdComment

nitc :: commands_http $ CmdComment

Retrieve the MDoc related to a MEntity
redef class CmdDescendants

nitc :: commands_http $ CmdDescendants

MEntity descendants command
redef class CmdEntity

nitc :: commands_http $ CmdEntity

A command about a MEntity
redef class CmdEntityCode

nitc :: commands_http $ CmdEntityCode

Cmd that finds the source code related to an mentity
redef abstract class CmdEntityList

nitc :: commands_http $ CmdEntityList

A command about a MEntity that returns a list of mentities
redef abstract class CmdError

nitc :: commands_http $ CmdError

Command Error
redef abstract class CmdGraph

nitc :: commands_http $ CmdGraph

An abstract command that returns a dot graph
redef class CmdInheritanceGraph

nitc :: commands_http $ CmdInheritanceGraph

Render a hierarchy graph for mentity if any.
redef abstract class CmdList

nitc :: commands_http $ CmdList

A command that returns a list of results
redef abstract class CmdMessage

nitc :: commands_http $ CmdMessage

Command message
redef class CmdModelEntities

nitc :: commands_http $ CmdModelEntities

A command that returns a list of all mentities in a model
redef class CmdSearch

nitc :: commands_http $ CmdSearch

A free text search command
redef abstract class CmdWarning

nitc :: commands_http $ CmdWarning

Command Warning
redef abstract class DocCommand

nitc :: commands_http $ DocCommand

Documentation command
redef class ErrorMEntityConflict

nitc :: commands_http $ ErrorMEntityConflict

Multiple MEntities matching mentity_name
redef class ErrorMEntityNoName

nitc :: commands_http $ ErrorMEntityNoName

No MEntity name provided
redef class ErrorMEntityNotFound

nitc :: commands_http $ ErrorMEntityNotFound

No MEntity matching mentity_name
redef class HttpRequest

nitc :: commands_http $ HttpRequest

A request received over HTTP, is build by HttpRequestParser
package_diagram nitc::commands_http commands_http nitc::commands_catalog commands_catalog nitc::commands_http->nitc::commands_catalog nitc::commands_graph commands_graph nitc::commands_http->nitc::commands_graph nitc::commands_ini commands_ini nitc::commands_http->nitc::commands_ini nitc::commands_main commands_main nitc::commands_http->nitc::commands_main nitc::commands_usage commands_usage nitc::commands_http->nitc::commands_usage nitcorn::vararg_routes vararg_routes nitc::commands_http->nitcorn::vararg_routes nitc::commands_model commands_model nitc::commands_catalog->nitc::commands_model nitc\>catalog\> catalog nitc::commands_catalog->nitc\>catalog\> nitc::commands_graph->nitc::commands_model nitc\>uml\> uml nitc::commands_graph->nitc\>uml\> dot dot nitc::commands_graph->dot nitc::commands_ini->nitc::commands_model nitc::commands_main->nitc::commands_model nitc::commands_usage->nitc::commands_model nitc\>semantize\> semantize nitc::commands_usage->nitc\>semantize\> nitcorn::server_config server_config nitcorn::vararg_routes->nitcorn::server_config nitcorn::http_request http_request nitcorn::vararg_routes->nitcorn::http_request ...nitc::commands_model ... ...nitc::commands_model->nitc::commands_model ...nitc\>catalog\> ... ...nitc\>catalog\>->nitc\>catalog\> ...nitc\>uml\> ... ...nitc\>uml\>->nitc\>uml\> ...dot ... ...dot->dot ...nitc\>semantize\> ... ...nitc\>semantize\>->nitc\>semantize\> ...nitcorn::server_config ... ...nitcorn::server_config->nitcorn::server_config ...nitcorn::http_request ... ...nitcorn::http_request->nitcorn::http_request nitc::api_base api_base nitc::api_base->nitc::commands_http nitc::api_auth api_auth nitc::api_auth->nitc::api_base nitc::api_model api_model nitc::api_model->nitc::api_base nitc::api_metrics api_metrics nitc::api_metrics->nitc::api_base nitc::api_feedback api_feedback nitc::api_feedback->nitc::api_base nitc::api_light api_light nitc::api_light->nitc::api_base nitc::api_auth... ... nitc::api_auth...->nitc::api_auth nitc::api_model... ... nitc::api_model...->nitc::api_model nitc::api_metrics... ... nitc::api_metrics...->nitc::api_metrics nitc::api_feedback... ... nitc::api_feedback...->nitc::api_feedback nitc::api_light... ... nitc::api_light...->nitc::api_light

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module abstract_tree

trees :: abstract_tree

Introduce tree structures abstraction
module annotation

nitc :: annotation

Management and utilities on annotations
module array

core :: array

This module introduces the standard array structure.
module auto_super_init

nitc :: auto_super_init

Computing of super-constructors that must be implicitly called at the begin of constructors.
module bintree

trees :: bintree

Binary Tree data-structure
module bitset

core :: bitset

Services to handle BitSet
module bktree

trees :: bktree

Implementation of BKTree
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module catalog

nitc :: catalog

Basic catalog generator for Nit packages
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module commands_base

nitc :: commands_base

Documentation commands
module commands_model

nitc :: commands_model

Doc commands about a Model or a MEntity
module console

console :: console

Defines some ANSI Terminal Control Escape Sequences.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module counter

counter :: counter

Simple numerical statistical analysis and presentation
module digraph

graph :: digraph

Implementation of directed graphs, also called digraphs.
module dot

dot :: dot

Dot rendering library
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module flow

nitc :: flow

Intraprocedural static flow.
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module http_request

nitcorn :: http_request

Provides the HttpRequest class and services to create it
module ini

ini :: ini

Read and write INI configuration files
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module lexer

nitc :: lexer

Lexer and its tokens.
module lexer_work

nitc :: lexer_work

Internal algorithm and data structures for the Nit lexer
module list

core :: list

This module handle double linked lists
module literal

nitc :: literal

Parsing of literal values in the abstract syntax tree.
module loader

nitc :: loader

Loading of Nit source files
module local_var_init

nitc :: local_var_init

Verify that local variables are initialized before their usage
module location

nitc :: location

Nit source-file and locations in source-file
module math

core :: math

Mathematical operations
module md5

md5 :: md5

Native MD5 digest implementation as Text::md5
module mdoc

nitc :: mdoc

Documentation of model entities
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module mmodule

nitc :: mmodule

modules and module hierarchies in the metamodel
module mmodule_data

nitc :: mmodule_data

Define and retrieve data in modules
module model

nitc :: model

Classes, types and properties
module model_base

nitc :: model_base

The abstract concept of model and related common things
module model_collect

nitc :: model_collect

Collect things from the model.
module model_examples

nitc :: model_examples

Examples for Model entities
module model_index

nitc :: model_index

Search things from the Model
module modelbuilder_base

nitc :: modelbuilder_base

Load nit source files and build the associated model
module modelize

nitc :: modelize

Create a model from nit source files
module modelize_class

nitc :: modelize_class

Analysis and verification of class definitions to instantiate model element
module modelize_property

nitc :: modelize_property

Analysis and verification of property definitions to instantiate model element
module more_collections

more_collections :: more_collections

Highly specific, but useful, collections-related classes.
module mpackage

nitc :: mpackage

Modelisation of a Nit package
module native

core :: native

Native structures for text and bytes
module nitpm_shared

nitc :: nitpm_shared

Services related to the Nit package manager
module numeric

core :: numeric

Advanced services for Numeric types
module opts

opts :: opts

Management of options on the command line
module ordered_tree

ordered_tree :: ordered_tree

Manipulation and presentation of ordered trees.
module parse_annotations

nitc :: parse_annotations

Simple annotation parsing
module parser

nitc :: parser

Parser.
module parser_nodes

nitc :: parser_nodes

AST nodes of the Nit language
module parser_prod

nitc :: parser_prod

Production AST nodes full definition.
module parser_work

nitc :: parser_work

Internal algorithm and data structures for the Nit parser
module phase

nitc :: phase

Phases of the processing of nit programs
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module rbtree

trees :: rbtree

A red–black tree is a data structure which is a type of self-balancing binary search tree.
module re

core :: re

Regular expression support for all services based on Pattern
module ropes

core :: ropes

Tree-based representation of a String.
module scope

nitc :: scope

Identification and scoping of local variables and labels.
module semantize

nitc :: semantize

Process bodies of methods in regard with the model.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module server_config

nitcorn :: server_config

Classes and services to configure the server
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module tables

nitc :: tables

Module that interfaces the parsing tables.
module template

template :: template

Basic template system
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module toolcontext

nitc :: toolcontext

Common command-line tool infrastructure than handle options and error messages
module trees

trees :: trees

General module for tree data structures
module trie

trees :: trie

A trie (or prefix tree) is a datastructure used to perform prefix searches.
module typing

nitc :: typing

Intraprocedural resolution of static types and OO-services
module uml

nitc :: uml

Group head module for UML generation services
module uml_base

nitc :: uml_base

Exposes the base class for UML generation of a Model
module uml_class

nitc :: uml_class

Provides facilities of exporting a Model to a UML class diagram
module uml_module

nitc :: uml_module

Services for generation of a UML package diagram based on a Model
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O
module version

nitc :: version

This file was generated by git-gen-version.sh

Parents

module commands_catalog

nitc :: commands_catalog

Commands to retrieve Catalog related data
module commands_graph

nitc :: commands_graph

Graph commands
module commands_usage

nitc :: commands_usage

Commands about how mentities are used
module vararg_routes

nitcorn :: vararg_routes

Routes with parameters.

Children

module api_base

nitc :: api_base

Base classes used by nitweb.

Descendants

module a_star-m

a_star-m

module api

nitc :: api

Components required to build a web server about the nit model.
module api_auth

nitc :: api_auth

module api_docdown

nitc :: api_docdown

Nitdoc specific Markdown format handling for Nitweb
module api_feedback

nitc :: api_feedback

Feedback related features
module api_light

nitc :: api_light

Highlight and collect messages from a piece of code
module api_model

nitc :: api_model

module nitweb

nitc :: nitweb

Runs a webserver based on nitcorn that render things from model.
# Initialize commands from HTTP requests
#
# FIXME: this module is pretty tied up to the nitwed routes.
# To be more generic, param names should be extracted as variables.
module commands_http

import commands_catalog
import commands_graph
import commands_ini
import commands_main
import commands_usage

import nitcorn::vararg_routes

redef class DocCommand
	# Init the command from an HTTPRequest
	fun http_init(req: HttpRequest): CmdMessage do
		var filter = cmd_filter
		var opt_vis = req.visibility_arg("min-visibility")
		if opt_vis != null then filter.min_visibility = opt_vis
		var opt_fictive = req.bool_arg("no-fictive")
		if opt_fictive != null then filter.accept_fictive = not opt_fictive
		var opt_test = req.bool_arg("no-test")
		if opt_test != null then filter.accept_test = not opt_test
		var opt_redef = req.bool_arg("no-redef")
		if opt_redef != null then filter.accept_redef = not opt_redef
		var opt_extern = req.bool_arg("no-extern")
		if opt_extern != null then filter.accept_extern = not opt_extern
		var opt_example = req.bool_arg("no-example")
		if opt_example != null then filter.accept_example = not opt_example
		var opt_attr = req.bool_arg("no-attribute")
		if opt_attr != null then filter.accept_attribute = not opt_attr
		var opt_doc = req.bool_arg("no-empty-doc")
		if opt_doc != null then filter.accept_empty_doc = not opt_doc
		var opt_inh = req.mentity_arg(model, "inherit")
		if opt_inh != null then filter.accept_inherited = opt_inh
		var opt_match = req.string_arg("match")
		if opt_match != null then filter.accept_full_name = opt_match
		self.filter = filter
		return init_command
	end
end

redef class CmdEntity
	redef fun http_init(req) do
		var name = req.param("id")
		if name != null then name = name.from_percent_encoding
		self.mentity_name = name

		return super
	end
end

redef class CmdList
	redef fun http_init(req) do
		var opt_limit = req.int_arg("l")
		if opt_limit != null then limit = opt_limit
		var opt_page = req.int_arg("p")
		if opt_page != null then page = opt_page
		return super
	end
end

# Error Handling

# Message handling

redef class CmdMessage
	# HTTP code to return for this message
	var http_status_code = 200
end

redef class CmdError
	redef var http_status_code = 400
end

redef class CmdWarning
	redef var http_status_code = 404
end

redef class ErrorMEntityNoName
	redef var http_status_code = 400
end

redef class ErrorMEntityNotFound
	redef var http_status_code = 404
end

redef class ErrorMEntityConflict
	redef var http_status_code = 300
end

# CmdModel

redef class CmdComment
	redef fun http_init(req) do
		var opt_full_doc = req.bool_arg("full_doc")
		if opt_full_doc != null then full_doc = opt_full_doc
		var opt_fallback = req.bool_arg("fallback")
		if opt_fallback != null then fallback = opt_fallback
		var opt_format = req.string_arg("format")
		if opt_format != null then format = opt_format
		return super
	end
end

redef class CmdEntityLink
	redef fun http_init(req) do
		var opt_text = req.string_arg("text")
		if opt_text != null then text = opt_text
		var opt_title = req.string_arg("title")
		if opt_title != null then title = opt_title
		return super
	end
end

redef class CmdAncestors
	redef fun http_init(req) do
		var opt_parents = req.bool_arg("parents")
		if opt_parents != null then parents = opt_parents
		return super
	end
end

redef class CmdDescendants
	redef fun http_init(req) do
		var opt_children = req.bool_arg("children")
		if opt_children != null then children = opt_children
		return super
	end
end

redef class CmdEntityList
	# FIXME avoid linearization conflict
	redef fun http_init(req) do return super
end

redef class CmdSearch
	redef fun http_init(req) do
		query = req.string_arg("q")
		return super
	end
end

redef class CmdModelEntities
	redef fun http_init(req) do
		var opt_kind = req.string_arg("kind")
		if opt_kind != null then kind = opt_kind
		return super
	end
end

redef class CmdCode
	redef fun http_init(req) do
		var opt_format = req.string_arg("format")
		if opt_format != null then format = opt_format
		return super
	end
end

redef class CmdEntityCode
	# FIXME avoid linearization conflict
	redef fun http_init(req) do
		var name = req.param("id")
		if name != null then name = name.from_percent_encoding
		mentity_name = name

		var opt_format = req.string_arg("format")
		if opt_format != null then format = opt_format
		return init_command
	end
end

# CmdGraph

redef class CmdGraph
	redef fun http_init(req) do
		var opt_format = req.string_arg("format")
		if opt_format != null then format = opt_format
		return super
	end
end

redef class CmdInheritanceGraph
	redef fun http_init(req) do
		var opt_pdepth = req.int_arg("pdepth")
		if opt_pdepth != null then pdepth = opt_pdepth
		var opt_cdepth = req.int_arg("cdepth")
		if opt_cdepth != null then cdepth = opt_cdepth
		return super
	end
end

# CmdCatalog

redef class CmdCatalogTag
	redef fun http_init(req) do
		var tag = req.param("tid")
		if tag != null then tag = tag.from_percent_encoding
		self.tag = tag
		return super
	end
end

redef class CmdCatalogPerson
	redef fun http_init(req) do
		var name = req.param("pid")
		if name != null then name = name.from_percent_encoding
		self.person_name = name
		return super
	end
end

# Util

redef class HttpRequest

	# Map String visiblity name to MVisibility object
	var allowed_visibility: HashMap[String, MVisibility] is lazy do
		var res = new HashMap[String, MVisibility]
		res["public"] = public_visibility
		res["protected"] = protected_visibility
		res["private"] = private_visibility
		return res
	end

	# Get arg as a MVisibility
	#
	# Return `null` if no option with that `key` or if the value is not in
	# `allowed_visibility`.
	fun visibility_arg(key: String): nullable MVisibility do
		var value = string_arg(key)
		if value == null then return null
		if not allowed_visibility.keys.has(key) then return null
		return allowed_visibility[value]
	end

	# Get arg as a MEntity
	#
	# Lookup first by `MEntity::full_name` then by `MEntity::name`.
	# Return `null` if the mentity name does not exist or return a conflict.
	private fun mentity_arg(model: Model, key: String): nullable MEntity do
		var value = string_arg(key)
		if value == null or value.is_empty then return null

		var mentity = model.mentity_by_full_name(value)
		if mentity != null then return mentity

		var mentities = model.mentities_by_name(value)
		if mentities.is_empty or mentities.length > 1 then return null
		return mentities.first
	end
end
src/doc/commands/commands_http.nit:15,1--267,3