private static ImmutableArray ExpandInput()

in src/RefasmerExe/Program.cs [344:378]


    private static ImmutableArray<(string Path, string RelativeForOutput)> ExpandInput(string input, DirectoryInfo baseForRelativeInput, LoggerBase logger)
    {
        if (!_expandGlobs)
            return ImmutableArray.Create((input, Path.GetFileName(input)));

        // Is this item globbing?
        var indexOfGlob = input.IndexOfAny(new[] {'*', '?'});
        if (indexOfGlob < 0)
            return ImmutableArray.Create((input, Path.GetFileName(input)));

        // Cut into non-globbing base dir and globbing mask (if input is an abs path, otherwise we use currentdir)
        DirectoryInfo basedir;
        var indexOfSepBeforeGlob = input.LastIndexOfAny(new[] {'\\', '/'}, indexOfGlob, indexOfGlob);
        string mask;
        if(indexOfSepBeforeGlob >= 0)
        {
            var beforemask = input.Substring(0, indexOfSepBeforeGlob + 1);
            basedir = Path.IsPathRooted(beforemask) ? new DirectoryInfo(beforemask) : new DirectoryInfo(Path.Combine(baseForRelativeInput.FullName, beforemask));
            mask = input.Substring(indexOfSepBeforeGlob + 1);
        }
        else
        {
            basedir = baseForRelativeInput;
            mask = input;
        }

        var result = new Matcher(StringComparison.OrdinalIgnoreCase).AddInclude(mask).Execute(new DirectoryInfoWrapper(basedir));
        if(!result.HasMatches)
            throw new InvalidOperationException($"The pattern “{input}” didn't match any files at all. Were looking for “{mask}” under the “{basedir.FullName}” directory.");

        var expanded = result.Files.Select(match => (Path.Combine(basedir.FullName, match.Path), match.Path)).ToImmutableArray();

        logger.Info?.Invoke($"Expanded “{input}” into {expanded.Length:N0} files.");
        return expanded;
    }