/tools/dspec/main.d

http://github.com/wilkie/djehuty · D · 96 lines · 61 code · 26 blank · 9 comment · 2 complexity · 26d69e06ae31621e1a8371f8b116168e MD5 · raw file

  1. /*
  2. * dspec.d
  3. *
  4. * This tool will use the parser to parse specifications and produce tests
  5. *
  6. */
  7. import io.console;
  8. import core.main;
  9. import core.string;
  10. import core.unicode;
  11. import core.arguments;
  12. import core.application;
  13. import core.definitions;
  14. import filelist;
  15. import parser;
  16. import parsing.options;
  17. char[] usage = `dspec rev1
  18. USAGE: dspec [-I<PATH>]
  19. EXAMPLE: dspec -Ispecs/.`;
  20. class Opts : OptionParser {
  21. mixin Options!(
  22. "I", "Specify the path for the specs to be found, recursively",
  23. string, "the path",
  24. "-help", "View help and usage"
  25. );
  26. void onI(string path) {
  27. _path = path;
  28. }
  29. void onHelp() {
  30. showUsage();
  31. Djehuty.application.exit(0);
  32. }
  33. string path() {
  34. return _path;
  35. }
  36. string outputPath() {
  37. return _outputPath;
  38. }
  39. private:
  40. string _path = ".";
  41. string _outputPath = ".specs";
  42. }
  43. class Dspec : Application {
  44. static this() { new Dspec(); }
  45. this() {
  46. super("djehuty-dspec");
  47. }
  48. override void onApplicationStart() {
  49. // Parse Options
  50. options = new Opts();
  51. // Interpret arguments
  52. string path = options.path;
  53. string outputPath = options.outputPath;
  54. Console.putln("Starting on path ", path);
  55. // Get the list of spec files
  56. FileList files = new FileList();
  57. if (!(files.fetch(path))) {
  58. Console.putln("error");
  59. return;
  60. }
  61. Parser parser = new Parser();
  62. if (!(parser.parseFiles(path, outputPath, files))) {
  63. Console.putln("error");
  64. return;
  65. }
  66. Console.putln("Test Routines Built: test.d in ", path);
  67. }
  68. private:
  69. Opts options;
  70. }