getArgValue function

String getArgValue(
  1. List<String> args,
  2. String key
)

Retrieves the value associated with a specific command-line argument key.

This function searches the args list for the given key (e.g., '--clientId'). If the key is found, it returns the value immediately following it in the list.

args The list of command-line arguments. key The argument key to search for.

Throws an ArgumentError if the key is found but no value is provided after it.

Returns the string value associated with the argument key.

Implementation

String getArgValue(List<String> args, String key) {
  final index = args.indexOf(key);
  if (index == -1 || index + 1 >= args.length) {
    throw ArgumentError('Missing value for $key');
  }
  return args[index + 1];
}