effectiveArgs function
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/-hat the top level still flows to the runner's help — we only injectgeneratewhen the first non-flag arg looks like an actual positional/option value.- If the user really did invoke
generateexplicitly, 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];
}