getSource function

String getSource(
  1. Config config,
  2. ArgResults? gRes, {
  3. ArgResults? aRes,
  4. Map<String, String>? env,
})

get source input, order: define -> env -> yaml -> argResults -> rest first

Implementation

String getSource(
  Config config,
  ArgResults? gRes, {
  ArgResults? aRes,
  Map<String, String>? env,
}) {
  String? source = config.optionalString('source');
  source ??= gRes?.option('source');
  source ??= aRes?.rest.firstOrNull;

  if (source == null || source.isEmpty) {
    throw UsageException('err: required source', '');
  }

  if (source.trimLeft().startsWith('~')) {
    if (isWindows) source = source.replaceFirst('~', homePattern);
    source = expandTilde(source);
  }

  if (source.contains(varInputRegexp) && env != null) {
    source = expandVar(source, map: env);
  }

  if (source.contains(varInputRegexp)) {
    throw UsageException('err: undef.var. $source', '');
  }

  // if (source.startsWith('.')) source = expandDotPath(source);
  source = p.normalize(source);
  return source;
}