import commands::commands_usage
import commands::commands_catalog
import commands::commands_ini
+import commands::commands_main
# Parse string commands to create DocQueries
class CommandParser
"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",
+ "mains", "main-compile", "main-run", "main-opts", "testing",
"catalog", "stats", "tags", "tag", "person", "contrib", "maintain"] is writable
# List of commands usage and documentation
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`"
+ # Main
+ usage["mains: <name>"] = "display the list of main methods for `name`"
+ usage["main-compile: <name>"] = "display the nitc command to compile `name`"
+ usage["main-run: <name>"] = "display the command to run `name`"
+ usage["main-opts: <name>"] = "display the command options for `name`"
+ usage["testing: <name>"] = "display the nitunit command to test `name`"
return usage
end
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)
+ # CmdMain
+ if name == "mains" then return new CmdMains(view)
+ if name == "main-compile" then return new CmdMainCompile(view)
+ if name == "main-run" then return new CmdManSynopsis(view)
+ if name == "main-opts" then return new CmdManOptions(view)
+ if name == "testing" then return new CmdTesting(view)
# CmdCatalog
var catalog = self.catalog
if catalog != null then
var cmd = parser.parse("descendants: Object")
assert cmd isa CmdDescendants
assert parser.error == null
- assert cmd.results.as(not null).length == 20
+ assert cmd.results.as(not null).length == 22
end
fun test_cmd_parser_descendants_without_children is test do
var cmd = parser.parse("descendants: Object | children: false")
assert cmd isa CmdDescendants
assert parser.error == null
- assert cmd.results.as(not null).length == 8
+ assert cmd.results.as(not null).length == 9
end
# CmdSearch
assert content != null
assert not content.is_empty
end
+
+ # CmdMain
+
+ fun test_cmd_parser_mains is test do
+ var parser = new CommandParser(test_view, test_builder, test_catalog)
+ var cmd = parser.parse("mains: test_prog")
+ assert cmd isa CmdMains
+ assert parser.error == null
+
+ var results = cmd.results
+ assert results != null
+ assert results.length == 1
+ assert results.first.full_name == "test_prog::test_prog"
+ end
+
+ fun test_cmd_parser_main_compile is test do
+ var parser = new CommandParser(test_view, test_builder, test_catalog)
+ var cmd = parser.parse("main-compile: test_prog::test_prog")
+ assert cmd isa CmdMainCompile
+ assert parser.error == null
+
+ var command = cmd.command
+ assert command != null
+ assert command.has_prefix("nitc ")
+ assert command.has_suffix("test_prog.nit")
+ end
+
+ fun test_cmd_parser_testing is test do
+ var parser = new CommandParser(test_view, test_builder, test_catalog)
+ var cmd = parser.parse("testing: test_prog")
+ assert cmd isa CmdTesting
+ assert parser.error == null
+
+ var command = cmd.command
+ assert command != null
+ assert command.has_prefix("nitunit ")
+ assert command.has_suffix("/tests")
+ end
+
+ fun test_cmd_man_synopsis is test do
+ var parser = new CommandParser(test_view, test_builder, test_catalog)
+ var cmd = parser.parse("main-run: test_prog")
+ assert cmd isa CmdManSynopsis
+ assert parser.error == null
+
+ assert cmd.synopsis == "test_prog [*options*] ARGS..."
+ end
+
+ fun test_cmd_man_opions is test do
+ var parser = new CommandParser(test_view, test_builder, test_catalog)
+ var cmd = parser.parse("main-opts: test_prog")
+ assert cmd isa CmdManOptions
+ assert parser.error == null
+
+ var options = cmd.options
+ assert options != null
+ assert options["--opt1"] == "Option 1."
+ assert options["--opt2"] == "Option 2."
+ end
end