addFlag method

  1. @override
void addFlag(
  1. String name, {
  2. String? abbr,
  3. String? help,
  4. bool? defaultsTo = false,
  5. bool negatable = true,
  6. void callback(
    1. bool p1
    )?,
  7. bool hide = false,
  8. List<String> aliases = const [],
})

Defines a boolean flag.

This adds an Option with the given properties to options.

The abbr argument is a single-character string that can be used as a shorthand for this flag. For example, abbr: "a" will allow the user to pass -a to enable the flag.

The help argument is used by usage to describe this flag.

The defaultsTo argument indicates the value this flag will have if the user doesn't explicitly pass it in.

The negatable argument indicates whether this flag's value can be set to false. For example, if name is flag, the user can pass --no-flag to set its value to false.

The callback argument is invoked with the flag's value when the flag is parsed. Note that this makes argument parsing order-dependent in ways that are often surprising, and its use is discouraged in favor of reading values from the ArgResults.

If hide is true, this option won't be included in usage.

If aliases is provided, these are used as aliases for name. These aliases will not appear as keys in the options map.

Throws an ArgumentError if:

  • There is already an option named name.
  • There is already an option using abbreviation abbr.

Implementation

@override
void addFlag(
  String name, {
  String? abbr,
  String? help,
  bool? defaultsTo = false,
  bool negatable = true,
  // ignore: avoid_positional_boolean_parameters
  void Function(bool p1)? callback,
  bool hide = false,
  List<String> aliases = const [],
}) =>
    _argParser.addFlag(
      name,
      abbr: abbr,
      help: help,
      defaultsTo: defaultsTo,
      negatable: negatable,
      callback: callback,
      hide: hide,
      aliases: aliases,
    );