buildArgParser static method

ArgParser buildArgParser({
  1. bool verbose = false,
  2. bool includeHelpOption = true,
  3. int? usageLineLength,
})

Builds an arg parser for the DevTools server.

includeHelpOption should be set to false if this arg parser will be used in a Command subclass.

Implementation

static ArgParser buildArgParser({
  bool verbose = false,
  bool includeHelpOption = true,
  int? usageLineLength,
}) {
  final argParser = ArgParser(
    usageLineLength: usageLineLength,
  );

  if (includeHelpOption) {
    argParser.addFlag(
      argHelp,
      negatable: false,
      abbr: 'h',
      help: 'Prints help output.',
    );
  }
  argParser
    ..addFlag(
      argVersion,
      negatable: false,
      help: 'Prints the DevTools version.',
    )
    ..addFlag(
      argVerbose,
      negatable: false,
      abbr: 'v',
      help: 'Output more informational messages.',
    )
    ..addOption(
      argHost,
      valueHelp: 'host',
      help: 'Hostname to serve DevTools on (defaults to localhost).',
    )
    ..addOption(
      argPort,
      defaultsTo: '9100',
      valueHelp: 'port',
      help: 'Port to serve DevTools on; specify 0 to automatically use any '
          'available port.',
    )
    ..addOption(
      argDtdUri,
      valueHelp: 'uri',
      help: 'A URI pointing to a Dart Tooling Daemon that DevTools should '
          'interface with.',
    )
    ..addFlag(
      argLaunchBrowser,
      help:
          'Launches DevTools in a browser immediately at start.\n(defaults to on unless in --machine mode)',
    )
    ..addFlag(
      argMachine,
      negatable: false,
      help: 'Sets output format to JSON for consumption in tools.',
    )
    ..addSeparator('Memory profiling options:')
    ..addOption(
      argProfileMemory,
      valueHelp: 'file',
      defaultsTo: 'memory_samples.json',
      help:
          'Start devtools headlessly and write memory profiling samples to the '
          'indicated file.',
    );

  argParser.addSeparator('App size options:');

  argParser
    ..addOption(
      argAppSizeBase,
      aliases: ['appSizeBase'],
      valueHelp: 'file',
      help: 'Path to the base app size file used for app size debugging.',
    )
    ..addOption(
      argAppSizeTest,
      aliases: ['appSizeTest'],
      valueHelp: 'file',
      help:
          'Path to the test app size file used for app size debugging.\nThis '
          'file should only be specified if --$argAppSizeBase is also '
          'specified.',
      hide: !verbose,
    );

  if (verbose) {
    argParser.addSeparator('Advanced options:');
  }

  // Args to show for verbose mode.
  argParser
    ..addOption(
      argTryPorts,
      defaultsTo: DevToolsServer.defaultTryPorts.toString(),
      valueHelp: 'count',
      help: 'The number of ascending ports to try binding to before failing '
          'with an error.',
      hide: !verbose,
    )
    ..addOption(
      argDdsHost,
      defaultsTo: DevToolsServer.defaultDdsHost,
      valueHelp: 'bind-address',
      help:
          "The address the Dart Development Service (DDS) should attempt to "
          "bind to if a DDS instance isn't active and a VM service URI is "
          "provided.",
      hide: !verbose,
    )
    ..addOption(
      argDdsPort,
      defaultsTo: DevToolsServer.defaultDdsPort.toString(),
      valueHelp: 'port',
      help:
          "The address the Dart Development Service (DDS) should attempt to "
          "bind to if a DDS instance isn't active and a VM service URI is "
          "provided.",
      hide: !verbose,
    )
    ..addFlag(
      argEnableNotifications,
      negatable: false,
      help: 'Requests notification permissions immediately when a client '
          'connects back to the server.',
      hide: !verbose,
    )
    ..addFlag(
      argAllowEmbedding,
      help: 'Allow embedding DevTools inside an iframe.',
      hide: !verbose,
    )
    ..addFlag(
      argHeadlessMode,
      negatable: false,
      help: 'Causes the server to spawn Chrome in headless mode for use in '
          'automated testing.',
      hide: !verbose,
    )
    ..addFlag(
      argPrintDtd,
      negatable: false,
      help: 'Print the address of the Dart Tooling Daemon, if one is hosted '
          'by the DevTools server.',
      hide: !verbose,
    );

  // Deprecated and hidden args.
  // TODO: Remove this - prefer that clients use the rest arg.
  argParser
    ..addOption(
      argVmUri,
      defaultsTo: '',
      help: 'VM Service protocol URI.',
      hide: true,
    )

    // Development only args.
    ..addFlag(
      argDebugMode,
      negatable: false,
      help: 'Run a debug build of the DevTools web frontend.',
      hide: true,
    );

  return argParser;
}