Exemplo n.º 1
0
        /// <summary>
        /// Load a YAML formatted PDocumentOption object from disk.
        /// </summary>
        /// <param name="path">The file or directory path to load options from.</param>
        /// <param name="silentlyContinue">When false, if the file does not exist, and exception will be raised.</param>
        /// <returns></returns>
        public static PSDocumentOption FromFile(string path, bool silentlyContinue = false)
        {
            // Get a rooted file path instead of directory or relative path
            var filePath = GetFilePath(path: path);

            // Fallback to defaults even if file does not exist when silentlyContinue is true
            if (!File.Exists(filePath))
            {
                if (!silentlyContinue)
                {
                    throw new FileNotFoundException(PSDocsResources.OptionsNotFound, filePath);
                }
                else
                {
                    // Use the default options
                    return(Default.Clone());
                }
            }
            return(FromYaml(path: filePath, yaml: File.ReadAllText(filePath)));
        }