Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[CommandLine] Update test_all_lib to use the new CommandLine interfac…

…e. This exposes some missing functionality. Add some TODO notes for later.
  • Loading branch information...
commit 9279d5764f24069c0a25fda60e67c2dd6cfb8c1f 1 parent 07c7d41
awhitworth authored
View
6 src/commandline/Program.winxed
@@ -8,6 +8,12 @@
*/
class Rosella.CommandLine.Program
{
+ // TODO: Fix on_error semantics, so we aren't possibly passing an exception to
+ // a help function instead of an Arguments object.
+
+ // TODO: Add an ability to pass arguments to the main routine flag instead of
+ // in a single Arguments object.
+
var program_name; // The string name of the program
var default_mode; // The default ProgramMode
var arg_defs; // Hash of all argument definitions
View
7 src/commandline/ProgramMode.winxed
@@ -5,14 +5,15 @@
*/
class Rosella.CommandLine.ProgramMode
{
- // TODO: Provide an automated help feature where each named argument can
- // take a short description which can be printed
-
// TODO: Take an integer to use as the default exit code
// TODO: Take a list of handles to use as the interpreter default during
// execution
+ // TODO: Add a mechanism to require a certain number of positional arguments
+
+ // TODO: Add an aliasing ability to give names to positional arguments
+
var name; // The name of the mode
var func; // The function to call
var conditions; // The conditions that determine if we use this mode
View
37 src/utilities/test_all_lib.winxed
@@ -3,11 +3,17 @@ function main[main](var args)
{
Rosella.Query.install_to_parrot_types();
var p = new Rosella.CommandLine.Program(args.shift());
- p.default_mode().set_function(test_all_main)
- .require_positional("language", 0)
- .require_positional("libpath", 1)
- .require_positional("folder", 2);
- p.add_mode("help").set_flag("--help").set_function(usage_and_exit);
+ p
+ .define_arguments({
+ "help|h" : "Show the help message"
+ })
+ .set_description("Create tests for all classes and namespaces in <library>. Output all tests\n" +
+ "to <folder>. Tests will be in language <lang>. <lang> is probably one of\n" +
+ "'winxed' or 'nqp' or others if you have suitable templates installed.");
+ p.default_mode()
+ .set_function(test_all_main)
+ .set_usage("<lang> <library> <folder>");
+ p.add_mode("help").require_flag("help").set_function(usage_and_exit);
p.on_error(usage_and_exit);
p.run(args);
}
@@ -15,9 +21,9 @@ function main[main](var args)
// Main handler. Pull out the arguments by name and run the program.
function test_all_main(var args)
{
- string libpath = args["libpath"];
- string lang = args["language"];
- string folder = args["folder"];
+ string libpath = args[1];
+ string lang = args[0];
+ string folder = args[2];
var module = Rosella.Reflect.Module.load(libpath);
var engine = new Rosella.Template.Engine();
@@ -61,20 +67,7 @@ function usage_and_exit(var args)
for (string bt in args.backtrace_strings())
say(bt);
}
- string prog_name;
- if (args == null || args instanceof 'Exception')
- prog_name = "rosella_test_all_lib";
- else
- prog_name = (new Rosella.FileSystem.FilePath(args.program_name())).short_name();
- string fmt = <<:
-Usage: %s <lang> <library> <folder>
-
-Create tests for all classes and namespaces in <library>. Output all tests
-to <folder>. Tests will be in language <lang>. <lang> is probably one of
-'winxed' or 'nqp' or others if you have suitable templates installed.
-:>>
-;
- Rosella.IO.sayf(fmt, prog_name);
+ say(args.program.get_help_text());
}
// Get the Directory object for the given namespace
Please sign in to comment.
Something went wrong with that request. Please try again.