internal CommandPathSearch(
            string commandName,
            LookupPathCollection lookupPaths,
            ExecutionContext context,
            Collection <string>?acceptableCommandNames,
            bool useFuzzyMatch)
        {
            _useFuzzyMatch = useFuzzyMatch;
            string[] commandPatterns;
            if (acceptableCommandNames != null)
            {
                // The name passed in is not a pattern. To minimize enumerating the file system, we
                // turn the command name into a pattern and then match against extensions in PATHEXT.
                // The old code would enumerate the file system many more times, once per possible extension.
                if (Platform.IsWindows)
                {
                    commandPatterns = new[] { commandName + ".*" };
                }
                else
                {
                    // Porting note: on non-Windows platforms, we want to always allow just 'commandName'
                    // as an acceptable command name. However, we also want to allow commands to be
                    // called with the .ps1 extension, so that 'script.ps1' can be called by 'script'.
                    commandPatterns = new[] { commandName, commandName + ".ps1" };
                }

                _postProcessEnumeratedFiles = CheckAgainstAcceptableCommandNames;
                _acceptableCommandNames     = acceptableCommandNames;
            }
            else
            {
                commandPatterns             = new[] { commandName };
                _postProcessEnumeratedFiles = JustCheckExtensions;
            }

            // Note, discovery must be set before resolving the current directory
            _context     = context;
            _patterns    = commandPatterns;
            _lookupPaths = lookupPaths;
            ResolveCurrentDirectoryInLookupPaths();

            _orderedPathExt = CommandDiscovery.PathExtensionsWithPs1Prepended;

            // The same as in this.Reset()
            _lookupPathsEnumerator             = _lookupPaths.GetEnumerator();
            _patternEnumerator                 = _patterns.GetEnumerator();
            _currentDirectoryResults           = Array.Empty <string>();
            _currentDirectoryResultsEnumerator = _currentDirectoryResults.GetEnumerator();
            _justReset = true;
        }