doc/commands: parse `commands_ini`
authorAlexandre Terrasa <alexandre@moz-code.org>
Wed, 2 May 2018 23:39:39 +0000 (19:39 -0400)
committerAlexandre Terrasa <alexandre@moz-code.org>
Tue, 8 May 2018 19:48:00 +0000 (15:48 -0400)
Signed-off-by: Alexandre Terrasa <alexandre@moz-code.org>

src/doc/commands/commands_parser.nit
src/doc/commands/tests/test_commands_parser.nit

index a6b439e..7ae94e2 100644 (file)
@@ -21,6 +21,7 @@ import commands::commands_model
 import commands::commands_graph
 import commands::commands_usage
 import commands::commands_catalog
+import commands::commands_ini
 
 # Parse string commands to create DocQueries
 class CommandParser
@@ -39,6 +40,8 @@ class CommandParser
        "link", "doc", "code", "lin", "uml", "graph", "search",
        "parents", "ancestors", "children", "descendants",
        "param", "return", "new", "call", "defs", "list", "random",
+       "ini-desc", "ini-git", "ini-issues", "ini-maintainer", "ini-contributors", "ini-license",
+       "license-file", "contrib-file", "license-content", "contrib-content", "git-clone",
        "catalog", "stats", "tags", "tag", "person", "contrib", "maintain"] is writable
 
        # List of commands usage and documentation
@@ -68,6 +71,18 @@ class CommandParser
                usage["tag: <tag>"] = "list all packages with `tag`"
                usage["maintain: <person>"] = "list all packages maintained by `person`"
                usage["contrib: <person>"] = "list all packages contributed by `person`"
+               # Ini commands
+               usage["ini-desc: <package>"] = "display the description from the `package` ini file"
+               usage["ini-git: <package>"] = "display the git url from the `package` ini file"
+               usage["ini-issues: <package>"] = "display the issues url from the `package` ini file"
+               usage["ini-license: <package>"] = "display the license from the `package` ini file"
+               usage["ini-maintainer: <package>"] = "display the maintainer from the `package` ini file"
+               usage["ini-contributors: <package>"] = "display the contributors from the `package` ini file"
+               usage["license-file: <package>"] = "display the license file for the `package`"
+               usage["license-content: <package>"] = "display the license file content for the `package`"
+               usage["contrib-file: <package>"] = "display the contrib file for the `package`"
+               usage["contrib-content: <package>"] = "display the contrib file content for the `package`"
+               usage["git-clone: <package>"] = "display the git clone command for the `package`"
                return usage
        end
 
@@ -174,6 +189,18 @@ class CommandParser
                # CmdModel
                if name == "list" then return new CmdModelEntities(view)
                if name == "random" then return new CmdRandomEntities(view)
+               # Ini
+               if name == "ini-desc" then return new CmdIniDescription(view)
+               if name == "ini-git" then return new CmdIniGitUrl(view)
+               if name == "ini-issues" then return new CmdIniIssuesUrl(view)
+               if name == "ini-license" then return new CmdIniLicense(view)
+               if name == "ini-maintainer" then return new CmdIniMaintainer(view)
+               if name == "ini-contributors" then return new CmdIniContributors(view)
+               if name == "license-file" then return new CmdLicenseFile(view)
+               if name == "license-content" then return new CmdLicenseFileContent(view)
+               if name == "contrib-file" then return new CmdContribFile(view)
+               if name == "contrib-content" then return new CmdContribFileContent(view)
+               if name == "git-clone" then return new CmdIniCloneCommand(view)
                # CmdCatalog
                var catalog = self.catalog
                if catalog != null then
index 1091d1d..d59b445 100644 (file)
@@ -402,4 +402,106 @@ class TestCommandsParser
                assert cmd.person.as(not null).name == "Alexandre Terrasa"
                assert cmd.results != null
        end
+
+       # CmdInit
+
+       fun test_cmd_parser_ini_desc is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("ini-desc: test_prog")
+               assert cmd isa CmdIniDescription
+               assert parser.error == null
+               assert cmd.desc.as(not null) == "Dummy program used for testing Nit tools"
+       end
+
+       fun test_cmd_parser_ini_git is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("ini-git: test_prog")
+               assert cmd isa CmdIniGitUrl
+               assert parser.error == null
+               assert cmd.url == "https://github.com/nitlang/nit.git"
+       end
+
+       fun test_cmd_parser_ini_clone is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("git-clone: test_prog")
+               assert cmd isa CmdIniCloneCommand
+               assert parser.error == null
+               assert cmd.url == "https://github.com/nitlang/nit.git"
+               assert cmd.command == "git clone https://github.com/nitlang/nit.git"
+       end
+
+       fun test_cmd_parser_ini_issues is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("ini-issues: test_prog")
+               assert cmd isa CmdIniIssuesUrl
+               assert parser.error == null
+               assert cmd.url == "https://github.com/nitlang/nit/issues"
+       end
+
+       fun test_cmd_parser_ini_maintainer is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("ini-maintainer: test_prog")
+               assert cmd isa CmdIniMaintainer
+               assert parser.error == null
+               assert cmd.maintainer == "John Doe <jdoe@example.com> (http://www.example.com/~jdoe), Spider-Man"
+       end
+
+       fun test_cmd_parser_ini_contributors is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("ini-contributors: test_prog")
+               assert cmd isa CmdIniContributors
+               assert parser.error == null
+               assert cmd.contributors == [
+                       "Riri <riri@example.com>",
+                       "Fifi (http://www.example.com/~fifi)",
+                       "Loulou"]
+       end
+
+       fun test_cmd_parser_ini_license is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("ini-license: test_prog")
+               assert cmd isa CmdIniLicense
+               assert parser.error == null
+               assert cmd.license == "Apache-2.0"
+       end
+
+       fun test_cmd_parser_ini_license_file is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("license-file: test_prog")
+               assert cmd isa CmdLicenseFile
+               assert parser.error == null
+               var file = cmd.file
+               assert file != null
+               assert file.basename == "LICENSE.md"
+       end
+
+       fun test_cmd_parser_ini_license_content is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("license-content: test_prog")
+               assert cmd isa CmdLicenseFileContent
+               assert parser.error == null
+               var content = cmd.content
+               assert content != null
+               assert not content.is_empty
+       end
+
+       fun test_cmd_parser_ini_contrib_file is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("contrib-file: test_prog")
+               assert cmd isa CmdContribFile
+               assert parser.error == null
+               var file = cmd.file
+               assert file != null
+               assert file.basename == "CONTRIBUTING.md"
+       end
+
+       fun test_cmd_parser_ini_contrib_content is test do
+               var parser = new CommandParser(test_view, test_builder, test_catalog)
+               var cmd = parser.parse("contrib-content: test_prog")
+               assert cmd isa CmdContribFileContent
+               assert parser.error == null
+               var content = cmd.content
+               assert content != null
+               assert not content.is_empty
+       end
 end