zaart function

void zaart (
  1. List<String> args
)

entry point for zaart command line application. this function parses args. args are passed into this tool from command prompt

Implementation

void zaart(List<String> args) async {
  _setupLogger();

  var context = Map();
  context["name"] = DEFAULT_TITLE;
  context["config"] = ZAART_CONFIG_FILE;
  context["cmd-init"] = Map();
  context["cmd-page"] = Map();
  context["cmd-publish"] = Map();
  context["cmd-unpublish"] = Map();
  context["cmd-build"] = Map();

  var argParser = ArgParser();
  _defInitCmd(argParser, context);
  _defPageCmd(argParser, context);
  _defBuildCmd(argParser, context);

  argParser.addFlag("help", abbr: "h", defaultsTo: false, callback: _printHelp);
  argParser.addFlag("version",
      abbr: "v", defaultsTo: false, callback: _printVersion);

  ArgResults res;

  try {
    res = argParser.parse(args);
  } catch (err) {
    Logger.root.severe(err);
    print("i do not understand what you mean!");
    print("use help command for more HELP!");
    print(err);
    return;
  }

  if (res.command == null) {
    print("what do you want me to do for you?");
    if (res.arguments.length > 0) {
      print("command '${res.arguments[0]}' is not known!");
    }
    return;
  }

  switch (res.command.name) {
    case "init":
      cmdInit(context);
      break;
    case "page":
      cmdPage(context);
      break;
    case "build":
      cmdBuild(context);
      break;
    default:
      print("oops, '${res.command.name}' is not a valid command");
      break;
  }
}