예제 #1
0
        private static IEnumerable<PathNode> EnumeratePathsToProcess(IReadOnlyList<PathNode> paths)
        {
            IEnumerable<List<PathNode>> result;
            if (paths.Count == 0)
            {
                result = new PathNode(Environment.CurrentDirectory, false)
                    .EnumerateTreeRecursively(EnumeratePathToProcess, EnumerableExtensions.TreeTraversalOrder.PostOrder);
            }
            else
            {
                result = paths.SelectMany(path =>
                    path.EnumerateTreeRecursively(EnumeratePathToProcess, EnumerableExtensions.TreeTraversalOrder.PostOrder));
            }

            if (_options.Clean)
                return result.Select(strs => strs[0])
                    .Where(node => File.Exists(node.Path));
            return result.Select(strs => strs[0])
                .Where(node => File.Exists(node.Path))
                .Where(node => node.IsIncluded);
        }
예제 #2
0
        private static IEnumerable<PathNode> EnumeratePathToProcess(Stack<PathNode> pathsStack)
        {
            var node = pathsStack.Peek();
            var path = node.Path;

            if (_options.Verbose)
            {
                var nodeChar = node.IsIncluded ? "T" : "F";
                Console.WriteLine($"{nodeChar} {path.RelativeTo(Environment.CurrentDirectory)}");
            }

            if (path == "-")
            {
                return ReadLinesFromInput()
                    .Where(str => !string.IsNullOrWhiteSpace(str))
                    .Select(str => Path.IsPathRooted(str) ? str : $"{Environment.CurrentDirectory}\\{str}")
                    .Select(str => new PathNode(str, true));
            }

            if (Directory.Exists(path))
            {
                return Directory.EnumerateFileSystemEntries(path)
                    .Where(str => Path.GetFileName(str) != ".git")
                    .Select(str => new PathNode(str, node.IsIncluded));
            }

            if (!File.Exists(path))
                return EnumerableUtility.EmptyArray<PathNode>();

            if (Path.GetFileName(path) == GitUntrackFileName)
            {
                return File.ReadLines(path)
                    .Select((str, i) =>
                    {
                        if (string.IsNullOrWhiteSpace(str))
                            return null;
                        var result = new PathNode(Path.IsPathRooted(str) ? str : $"{Path.GetDirectoryName(path)}\\{str}", path, i);
                        return result;
                    });
            }

            return EnumerableUtility.EmptyArray<PathNode>();
        }