ni: cleaned options context
[nit.git] / src / ni.nit
index e340415..76a40b6 100644 (file)
@@ -36,9 +36,10 @@ class NitIndex
        init(toolcontext: ToolContext) do
                # We need a model to collect stufs
                self.toolcontext = toolcontext
+               self.toolcontext.option_context.options.clear
                self.arguments = toolcontext.option_context.rest
 
-               if arguments.length > 2 then
+               if arguments.is_empty or arguments.length > 2 then
                        print "usage: ni path/to/module.nit [expression]"
                        toolcontext.option_context.usage
                        exit(1)
@@ -88,11 +89,17 @@ class NitIndex
                if entry.has_prefix("return:") then
                        var ret = entry.split_with(":")[1].replace(" ", "")
                        var matches = seek_returns(ret)
-                       if not matches.is_empty then props_fulldoc(matches)
+                       if not matches.is_empty then
+                               flag = true
+                               props_fulldoc(matches)
+                       end
                else if entry.has_prefix("param:") then
                        var param = entry.split_with(":")[1].replace(" ", "")
                        var matches = seek_params(param)
-                       if not matches.is_empty then props_fulldoc(matches)
+                       if not matches.is_empty then
+                               flag = true
+                               props_fulldoc(matches)
+                       end
                else
                        # seek for modules
                        var mmatches = new List[MModule]
@@ -236,21 +243,23 @@ class NitIndex
        private fun props_fulldoc(raw_mprops: List[MProperty]) do
                var pager = new Pager
                # group by module
-               var cats = new HashMap[MModule, Array[MProperty]]
+               var cats = new HashMap[MClass, Array[MProperty]]
                for mprop in raw_mprops do
-                       var mmodule = mprop.intro_mclassdef.mmodule
-                       if not cats.has_key(mmodule) then cats[mmodule] = new Array[MProperty]
-                       cats[mmodule].add(mprop)
+                       if not mbuilder.mpropdef2npropdef.has_key(mprop.intro) then continue
+                       if mprop isa MAttribute then continue
+                       var mclass = mprop.intro_mclassdef.mclass
+                       if not cats.has_key(mclass) then cats[mclass] = new Array[MProperty]
+                       cats[mclass].add(mprop)
                end
                #sort groups
-               var sorter = new ComparableSorter[MModule]
-               var sorted = new Array[MModule]
+               var sorter = new ComparableSorter[MClass]
+               var sorted = new Array[MClass]
                sorted.add_all(cats.keys)
                sorter.sort(sorted)
                # display
-               for mmodule in sorted do
-                       var mprops = cats[mmodule]
-                       pager.add("# {mmodule.namespace}".bold)
+               for mclass in sorted do
+                       var mprops = cats[mclass]
+                       pager.add("# {mclass.namespace}".bold)
                        var sorterp = new ComparableSorter[MProperty]
                        sorterp.sort(mprops)
                        for mprop in mprops do