formatSyntax method

String formatSyntax({
  1. bool withFlags = true,
})

Returns a help message describing the usage of the command and it's available flags.

withFlags will decide if the flags should also be printed into the syntax.

Implementation

String formatSyntax({final bool withFlags = true}) {
  String syntax = "$description\n";
  if (subCommands.isNotEmpty) {
    syntax = syntax + "\nAvailable commands:\n";
    int useLongest = 0;
    subCommands.forEach((cmd) {
      if (cmd.use.length > useLongest) {
        useLongest = cmd.use.length;
      }
    });
    for (final Command subCommand in subCommands) {
      if (subCommand.hidden) continue;
      final int space = useLongest + 3 - subCommand.use.length;
      syntax =
          syntax +
          subCommand.use +
          (" " * space) +
          subCommand.description +
          "\n";
    }
  }
  if (flags.isNotEmpty && withFlags) {
    syntax += "\nCommand avertable flags:\n";
    for (final Flag flag in flags) {
      syntax += flag.syntaxString() + "\n";
    }
  }
  if (flags.isEmpty && subCommands.isEmpty && !withFlags) {
    syntax += "\n";
  }
  return syntax;
}