effectiveArgs function

List<String> effectiveArgs(
  1. List<String> args
)

Returns the effective argument list for args.

If args is empty, or its first non-flag token is not one of knownSubcommands, we prepend 'generate' so that bare invocations (dart run flutter_launcher_icons_flavors -f my.yaml) keep behaving exactly as they did before the CommandRunner migration.

Two edge cases worth calling out:

  • --help / -h at the top level still flows to the runner's help — we only inject generate when the first non-flag arg looks like an actual positional/option value.
  • If the user really did invoke generate explicitly, we leave the args untouched.

Implementation

List<String> effectiveArgs(List<String> args) {
  if (args.isEmpty) {
    return const ['generate'];
  }
  // Top-level `--help` / `-h` should reach the runner unchanged so the
  // runner's own help banner fires.
  for (final a in args) {
    if (a == '--help' || a == '-h') {
      return args;
    }
    // Stop at the first non-flag token; that's the candidate
    // subcommand.
    if (!a.startsWith('-')) {
      if (knownSubcommands.contains(a)) {
        return args;
      }
      break;
    }
  }
  return ['generate', ...args];
}