protected virtual string ResolveFilePath()

in src/Common/Commands.Common/PowerBICmdlet.cs [196:252]


        protected virtual string ResolveFilePath(string path, bool isLiteralPath)
        {
            ProviderInfo provider = null;
            PSDriveInfo drive = null;
            var filePaths = new List<string>();

            if (this.SessionState != null)
            {
                try
                {
                    if (isLiteralPath)
                    {
                        filePaths.Add(this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(path, out provider, out drive));
                    }
                    else
                    {
                        filePaths.AddRange(this.SessionState.Path.GetResolvedProviderPathFromPSPath(path, out provider));
                    }

                    if (provider != null && !provider.Name.Contains("FileSystem"))
                    {
                        this.logger.ThrowTerminatingError(new NotSupportedException($"Unsupported PowerShell provider '{provider.Name}' for resolving path: {path}"));
                    }

                    if (filePaths.Count > 1)
                    {
                        this.logger.ThrowTerminatingError(new NotSupportedException("Multiple files not supported"), ErrorCategory.InvalidArgument);
                    }

                    if (filePaths.Count == 0)
                    {
                        this.logger.ThrowTerminatingError(new FileNotFoundException("Wildcard unable to find file"), ErrorCategory.OpenError);
                    }

                    return filePaths[0];
                }
                catch (ItemNotFoundException)
                {
                    path = this.SessionState.Path.GetUnresolvedProviderPathFromPSPath(path, out provider, out drive);
                    if (provider != null && !provider.Name.Contains("FileSystem"))
                    {
                        this.logger.ThrowTerminatingError(new NotSupportedException($"Unsupported PowerShell provider '{provider.Name}' for resolving path: {path}"));
                    }

                    return path;
                }
            }
            else
            {
                if (Path.IsPathRooted(path))
                {
                    return path;
                }

                return Path.Combine(this.CurrentPath, path);
            }
        }