expandLiveFileArguments function
Replaces arguments written as @path with the contents of that file, so
an option can take a file: --scenario @seeds/jane.json.
Works for --option=@path too. Start a value with @@ when it really
begins with @. Arguments after -- are left alone. Trailing newlines
are dropped, as $(cat path) does. Throws a FormatException when the
file doesn't exist.
Implementation
List<String> expandLiveFileArguments(List<String> arguments) {
final List<String> expanded = [];
for (int i = 0; i < arguments.length; i++) {
final String argument = arguments[i];
if (argument == '--') {
expanded.addAll(arguments.sublist(i));
break;
}
final int equals = argument.startsWith('--') ? argument.indexOf('=') : -1;
expanded.add(
equals == -1
? _fileValue(argument)
: '${argument.substring(0, equals + 1)}'
'${_fileValue(argument.substring(equals + 1))}',
);
}
return expanded;
}