Commands to retrieve Catalog related data

Introduced classes

abstract class CmdCatalog

nitc :: CmdCatalog

A DocCommand based on a Catalog
class CmdCatalogContributing

nitc :: CmdCatalogContributing

Retrieve the packages contributed by a person
class CmdCatalogMaintaining

nitc :: CmdCatalogMaintaining

Retrieve the packages maintained by a person
class CmdCatalogPackages

nitc :: CmdCatalogPackages

Retrieve the packages in the catalog
class CmdCatalogPerson

nitc :: CmdCatalogPerson

Retrieve a person from the catalog
class CmdCatalogSearch

nitc :: CmdCatalogSearch

A CmdSearch command using a Catalog
class CmdCatalogStats

nitc :: CmdCatalogStats

Retrieve the catalog stats
class CmdCatalogTag

nitc :: CmdCatalogTag

Retrieve the packages for a tag
class CmdCatalogTags

nitc :: CmdCatalogTags

Retrieve the catalog tags list
class CmdMetadata

nitc :: CmdMetadata

Retrieve the catalog metadata for a MPackage
class ErrorNoPerson

nitc :: ErrorNoPerson

No person instance or name provided
class ErrorNoTag

nitc :: ErrorNoTag

No tag name provided
class ErrorPersonNotFound

nitc :: ErrorPersonNotFound

No person found with this name
class ErrorTagNotFound

nitc :: ErrorTagNotFound

No tag with this name in the catalog
class WarningNoMetadata

nitc :: WarningNoMetadata

No metadata for mentity

All class definitions

abstract class CmdCatalog

nitc $ CmdCatalog

A DocCommand based on a Catalog
class CmdCatalogContributing

nitc $ CmdCatalogContributing

Retrieve the packages contributed by a person
class CmdCatalogMaintaining

nitc $ CmdCatalogMaintaining

Retrieve the packages maintained by a person
class CmdCatalogPackages

nitc $ CmdCatalogPackages

Retrieve the packages in the catalog
class CmdCatalogPerson

nitc $ CmdCatalogPerson

Retrieve a person from the catalog
class CmdCatalogSearch

nitc $ CmdCatalogSearch

A CmdSearch command using a Catalog
class CmdCatalogStats

nitc $ CmdCatalogStats

Retrieve the catalog stats
class CmdCatalogTag

nitc $ CmdCatalogTag

Retrieve the packages for a tag
class CmdCatalogTags

nitc $ CmdCatalogTags

Retrieve the catalog tags list
class CmdMetadata

nitc $ CmdMetadata

Retrieve the catalog metadata for a MPackage
class ErrorNoPerson

nitc $ ErrorNoPerson

No person instance or name provided
class ErrorNoTag

nitc $ ErrorNoTag

No tag name provided
class ErrorPersonNotFound

nitc $ ErrorPersonNotFound

No person found with this name
class ErrorTagNotFound

nitc $ ErrorTagNotFound

No tag with this name in the catalog
class WarningNoMetadata

nitc $ WarningNoMetadata

No metadata for mentity
package_diagram nitc::commands_catalog commands_catalog nitc::commands_model commands_model nitc::commands_catalog->nitc::commands_model nitc\>catalog\> catalog nitc::commands_catalog->nitc\>catalog\> nitc::commands_base commands_base nitc::commands_model->nitc::commands_base nitc\>modelize\> modelize nitc::commands_model->nitc\>modelize\> nitc\>catalog\>->nitc\>modelize\> md5 md5 nitc\>catalog\>->md5 counter counter nitc\>catalog\>->counter ...nitc::commands_base ... ...nitc::commands_base->nitc::commands_base ...nitc\>modelize\> ... ...nitc\>modelize\>->nitc\>modelize\> ...md5 ... ...md5->md5 ...counter ... ...counter->counter nitc::md_commands md_commands nitc::md_commands->nitc::commands_catalog nitc::commands_parser commands_parser nitc::commands_parser->nitc::commands_catalog nitc::commands_http commands_http nitc::commands_http->nitc::commands_catalog nitc::json_commands json_commands nitc::json_commands->nitc::commands_catalog nitc::commands_docdown commands_docdown nitc::commands_docdown->nitc::md_commands nitc::term term nitc::term->nitc::md_commands nitc::term->nitc::commands_parser nitc::commands_docdown... ... nitc::commands_docdown...->nitc::commands_docdown nitc::term... ... nitc::term...->nitc::term nitc::html_commands html_commands nitc::html_commands->nitc::commands_parser nitc::html_commands... ... nitc::html_commands...->nitc::html_commands nitc::api_base api_base nitc::api_base->nitc::commands_http nitc::api_base->nitc::json_commands nitc::api_base... ... nitc::api_base...->nitc::api_base

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 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 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 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 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 gc

core :: gc

Access to the Nit internal garbage collection mechanism
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
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 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 serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
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 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 catalog

nitc :: catalog

Basic catalog generator for Nit packages
module commands_model

nitc :: commands_model

Doc commands about a Model or a MEntity

Children

module commands_http

nitc :: commands_http

Initialize commands from HTTP requests
module commands_parser

nitc :: commands_parser

A parser that create DocCommand from a string
module json_commands

nitc :: json_commands

Translate command results to json
module md_commands

nitc :: md_commands

Render commands results as Markdown

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_base

nitc :: api_base

Base classes used by nitweb.
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 commands_docdown

nitc :: commands_docdown

Doc down related queries
module html_commands

nitc :: html_commands

Render commands results as HTML
module nitdoc

nitc :: nitdoc

Generator of static API documentation for the Nit language
module nitweb

nitc :: nitweb

Runs a webserver based on nitcorn that render things from model.
module nitx

nitc :: nitx

nitx, a command tool that displays useful data about Nit code
module static

nitc :: static

Nitdoc generation framework
module static_base

nitc :: static_base

Base entities shared by all the nitdoc code
module static_cards

nitc :: static_cards

Cards templates for the static documentation
module static_html

nitc :: static_html

Render documentation pages as HTML
module static_index

nitc :: static_index

Manage indexing of Nit model for Nitdoc QuickSearch.
module static_structure

nitc :: static_structure

Composes the pages of the static documentation
module term

nitc :: term

# Commands to retrieve Catalog related data
module commands_catalog

import commands_model
import catalog

# A DocCommand based on a Catalog
abstract class CmdCatalog
	super DocCommand

	autoinit(model, catalog, filter)

	# Catalog to query at
	var catalog: Catalog
end

# A CmdSearch command using a Catalog
class CmdCatalogSearch
	super CmdCatalog
	super CmdSearch

	autoinit(model, catalog, filter, query, limit, page, count, max)

	redef fun init_results do
		if results != null then return new CmdSuccess

		var res = super
		if not res isa CmdSuccess then return res

		var query = self.query
		if query == null then return new ErrorNoQuery
		sorter = null

		var filter = self.filter
		var index = model.index

		# lookup by name prefix
		var matches = index.find_by_name_prefix(query, filter).uniq.
			sort(lname_sorter, name_sorter, kind_sorter)
		matches = matches.rerank.sort(vis_sorter, score_sorter)

		# lookup by tags
		var malus = matches.length
		if catalog.tag2proj.has_key(query) then
			for mpackage in catalog.tag2proj[query] do
				if filter != null and not filter.accept_mentity(mpackage) then continue
				matches.add new IndexMatch(mpackage, malus)
				malus += 1
			end
			matches = matches.uniq.rerank.sort(vis_sorter, score_sorter)
		end

		# lookup by full_name prefix
		malus = matches.length
		var full_matches = new IndexMatches
		for match in index.find_by_full_name_prefix(query, filter).
			sort(lfname_sorter, fname_sorter) do
			match.score += 1
			full_matches.add match
		end
		matches = matches.uniq

		# lookup by similarity
		malus = matches.length
		var sim_matches = new IndexMatches
		for match in index.find_by_similarity(query, filter).sort(score_sorter, kind_sorter, lname_sorter, name_sorter) do
			if match.score > query.length then break
			match.score += 1
			sim_matches.add match
		end
		matches.add_all sim_matches
		matches = matches.uniq
		results = matches.rerank.sort(vis_sorter, score_sorter).mentities
		return res
	end

	private var score_sorter = new ScoreComparator
	private var vis_sorter = new VisibilityComparator
	private var name_sorter = new NameComparator
	private var lname_sorter = new NameLengthComparator
	private var fname_sorter = new FullNameComparator
	private var lfname_sorter = new FullNameLengthComparator
	private var kind_sorter = new MEntityComparator
end

# Retrieve the catalog metadata for a MPackage
class CmdMetadata
	super CmdEntity

	# MPackage metadata retrieved
	var metadata: nullable MPackageMetadata = null is optional, writable

	redef fun init_command do
		if metadata != null then return new CmdSuccess

		var res = super
		if not res isa CmdSuccess then return res
		var mentity = self.mentity.as(not null)

		if mentity isa MPackage then
			metadata = mentity.metadata
		else
			return new WarningNoMetadata(mentity)
		end
		return res
	end
end

# No metadata for `mentity`
class WarningNoMetadata
	super CmdWarning

	# MEntity provided
	var mentity: MEntity

	redef fun to_s do return "No metadata for `{mentity.full_name}`"
end

# Retrieve the packages in the catalog
class CmdCatalogPackages
	super CmdCatalog
	super CmdEntities

	autoinit(model, catalog, filter, limit, page, count, max)

	redef var sorter = new CatalogScoreSorter(catalog) is lazy

	redef fun init_results do
		if results != null then return new CmdSuccess

		var res = super
		if not res isa CmdSuccess then return res

		results = catalog.mpackages.values.to_a
		return res
	end
end

# Retrieve the catalog stats
class CmdCatalogStats
	super CmdCatalog

	# Retrieved catalog statistics
	var stats: nullable CatalogStats = null is optional, writable

	redef fun init_command do
		super
		self.stats = catalog.catalog_stats
		return new CmdSuccess
	end
end

# Retrieve the catalog tags list
class CmdCatalogTags
	super CmdCatalog

	# Sorter to sort tags alphabetically
	var tags_sorter = new CatalogTagsSorter is optional, writable

	# Count of packages by tag
	var packages_count_by_tags: nullable ArrayMap[String, Int] = null is optional, writable

	redef fun init_command do
		super
		var tags_to_projects = new ArrayMap[String, Int]
		var tags = catalog.tag2proj.keys.to_a
		tags_sorter.sort(tags)
		for tag in tags do
			if not catalog.tag2proj.has_key(tag) then continue
			tags_to_projects[tag] = catalog.tag2proj[tag].length
		end
		packages_count_by_tags = tags_to_projects
		return new CmdSuccess
	end
end

# Retrieve the packages for a tag
class CmdCatalogTag
	super CmdCatalogPackages

	autoinit(model, catalog, filter, tag, limit, page, count, max)

	# The tag to retrieve
	var tag: nullable String = null is optional, writable

	redef fun init_command do
		var tag = self.tag
		if tag == null then return new ErrorNoTag

		if not catalog.tag2proj.has_key(tag) then return new ErrorTagNotFound(tag)
		return super
	end

	redef fun init_results do
		if results != null then return new CmdSuccess

		var res = super
		if not res isa CmdSuccess then return res

		results = catalog.tag2proj[tag].to_a
		return res
	end
end

# No tag name provided
class ErrorNoTag
	super CmdError

	redef fun to_s do return "No tag name provided"
end

# No tag with this name in the catalog
class ErrorTagNotFound
	super CmdError

	# The tag that was not found
	var tag: String

	redef fun to_s do return "No tag found for `{tag}`"
end

# Retrieve a person from the catalog
class CmdCatalogPerson
	super CmdCatalog

	# Person to retrieve
	#
	# You can also pass a `person_name`.
	var person: nullable Person = null is optional, writable

	# Name of the person to retrieve
	#
	# You can also pass a `person` instance.
	var person_name: nullable String = null is optional, writable

	# Initialize the `person` result
	fun init_person: CmdMessage do
		var person = self.person
		if person != null then
			person_name = person.name
			return new CmdSuccess
		end

		var name = self.person_name
		if name == null then return new ErrorNoPerson
		if not catalog.name2person.has_key(name) then return new ErrorPersonNotFound(name)
		self.person = catalog.name2person[name]
		return new CmdSuccess
	end

	redef fun init_command do
		init_person
		return super
	end
end

# No person instance or name provided
class ErrorNoPerson
	super CmdError

	redef fun to_s do return "No person provided"
end

# No person found with this name
class ErrorPersonNotFound
	super CmdError

	# Name of the person that was not found
	var name: String

	redef fun to_s do return "No person found for `{name}`"
end

# Retrieve the packages maintained by a person
class CmdCatalogMaintaining
	super CmdCatalogPerson
	super CmdCatalogPackages

	autoinit(model, catalog, filter, person, person_name, limit, page, count, max)

	redef fun init_command do return super

	redef fun init_results do
		if results != null then return new CmdSuccess
		var res = super
		if not res isa CmdSuccess then return res
		var person = self.person.as(not null)

		if not catalog.maint2proj.has_key(person) then return res
		results = catalog.maint2proj[person]
		return res
	end
end

# Retrieve the packages contributed by a person
class CmdCatalogContributing
	super CmdCatalogPerson
	super CmdCatalogPackages

	autoinit(model, catalog, filter, person, person_name, limit, page, count, max)

	# Include maintained packages?
	#
	# Default is `false`.
	var maintaining = false is optional, writable

	# FIXME linearization
	redef fun init_command do return super

	redef fun init_results do
		if results != null then return new CmdSuccess

		var res = super
		if not res isa CmdSuccess then return res
		var person = self.person.as(not null)

		if not catalog.contrib2proj.has_key(person) then return res

		var maint2proj = null
		if catalog.maint2proj.has_key(person) then
			maint2proj = catalog.maint2proj[person]
		end

		var results = new Array[MPackage]
		for mpackage in catalog.contrib2proj[person] do
			if not maintaining and maint2proj != null and maint2proj.has(mpackage) then continue
			results.add mpackage
		end
		self.results = results
		return res
	end
end
src/doc/commands/commands_catalog.nit:15,1--346,3