Merge: src/doc/commands: clean commands hierarchy
[nit.git] / src / doc / commands / commands_base.nit
index fce0b61..bde3f8e 100644 (file)
 module commands_base
 
 import model::model_index
-import catalog
 
 # Documentation command
 #
-# An abstract command that works on a ModelView.
+# An abstract command that works on a Model.
 #
 # Since they are used by a wide variety of clients, initialization of DocCommands
 # works in two steps.
@@ -53,10 +52,11 @@ import catalog
 # See `init_command` for more details about the returned statuses.
 abstract class DocCommand
 
-       # ModelView
-       #
-       # Set of entities and filters used to retrieve data from the model.
-       var view: ModelView
+       # Model to retrieve data for
+       var model: Model
+
+       # ModelFilter to apply if any
+       var filter: nullable ModelFilter
 
        # Initialize the command
        #
@@ -69,6 +69,13 @@ abstract class DocCommand
        #
        # Warnings are generally used to distinguish empty list or mdoc from no data at all.
        fun init_command: CmdMessage do return new CmdSuccess
+
+       # Return a new filter for that command execution.
+       fun cmd_filter: ModelFilter do
+               var filter = self.filter
+               if filter == null then return new ModelFilter
+               return new ModelFilter.from(filter)
+       end
 end
 
 # Command message
@@ -138,13 +145,13 @@ class CmdEntity
                end
 
                var mentity_name = self.mentity_name
-               if mentity_name == null then return new ErrorMEntityNoName
+               if mentity_name == null or mentity_name.is_empty then return new ErrorMEntityNoName
 
-               mentity = view.mentity_by_full_name(mentity_name)
+               mentity = model.mentity_by_full_name(mentity_name)
                if mentity == null then
-                       var mentities = view.mentities_by_name(mentity_name)
+                       var mentities = model.mentities_by_name(mentity_name)
                        if mentities.is_empty then
-                               var suggest = view.find(mentity_name, 3)
+                               var suggest = model.find(mentity_name, 3)
                                return new ErrorMEntityNotFound(mentity_name, suggest)
                        else if mentities.length > 1 then
                                return new ErrorMEntityConflict(mentity_name, mentities)
@@ -312,7 +319,7 @@ abstract class CmdEntityList
        super CmdEntity
        super CmdEntities
 
-       autoinit(view, mentity, mentity_name, limit, page, count, max)
+       autoinit(model, filter, mentity, mentity_name, limit, page, count, max)
 
        redef fun init_command do
                var res = init_mentity