internal FileOutputWriter(PipelineWriter inner, PSRuleOption option, Encoding encoding, string path, ShouldProcess shouldProcess) : base(inner, option) { _Encoding = encoding; _Path = path; _ShouldProcess = shouldProcess; }
internal PipelineBuilderBase(Source[] source, HostContext hostContext) { Option = new PSDocumentOption(); Source = source; Writer = new HostPipelineWriter(hostContext); ShouldProcess = hostContext == null ? EmptyShouldProcess : hostContext.ShouldProcess; OutputVisitor = (o, enumerate) => WriteToString(o, enumerate, Writer); }
public void Archive_should_only_include_published_posts() { Assert.True(ShouldProcess.Archive(new Post { Published = Published.True })); Assert.False(ShouldProcess.Archive(new Post { Published = Published.Draft })); Assert.False(ShouldProcess.Archive(new Post { Published = Published.Private })); }
public void Categories_should_only_include_published_posts() { Assert.True(ShouldProcess.Category(new Post { Published = Published.True })); Assert.False(ShouldProcess.Category(new Post { Published = Published.Private })); Assert.False(ShouldProcess.Category(new Post { Published = Published.Draft })); }
/// <summary> /// Write output to file. /// </summary> /// <param name="path">The file path to write.</param> /// <param name="encoding">The file encoding to use.</param> /// <param name="o">The text to write.</param> private static void WriteToFile(string path, ShouldProcess shouldProcess, Encoding encoding, object o) { var rootedPath = PSRuleOption.GetRootedPath(path: path); var parentPath = Directory.GetParent(rootedPath); if (!parentPath.Exists && shouldProcess(target: parentPath.FullName, action: PSRuleResources.ShouldCreatePath)) { Directory.CreateDirectory(path: parentPath.FullName); } if (shouldProcess(target: rootedPath, action: PSRuleResources.ShouldWriteFile)) { File.WriteAllText(path: rootedPath, contents: o.ToString(), encoding: encoding); } }
/// <summary> /// Write output to file. /// </summary> /// <param name="path">The file path to write.</param> /// <param name="defaultFile">The default file name to use when a directory is specified.</param> /// <param name="encoding">The file encoding to use.</param> /// <param name="o">The text to write.</param> protected static void WriteToFile(string path, string defaultFile, ShouldProcess shouldProcess, WriteOutput output, Encoding encoding, object o) { var rootedPath = PSRuleOption.GetRootedPath(path: path); if (!Path.HasExtension(rootedPath) || Directory.Exists(rootedPath)) { rootedPath = Path.Combine(rootedPath, defaultFile); } var parentPath = Directory.GetParent(rootedPath); if (!parentPath.Exists && shouldProcess(target: parentPath.FullName, action: PSRuleResources.ShouldCreatePath)) { Directory.CreateDirectory(path: parentPath.FullName); } if (shouldProcess(target: rootedPath, action: PSRuleResources.ShouldWriteFile)) { File.WriteAllText(path: rootedPath, contents: o.ToString(), encoding: encoding); var info = new FileInfo(rootedPath); output(info, false); } }
public virtual void UseCommandRuntime(ICommandRuntime2 commandRuntime) { //Logger.UseCommandRuntime(commandRuntime); Output = commandRuntime.WriteObject; ShouldProcess = commandRuntime.ShouldProcess; }
private static void WriteToFile(IDocumentResult result, PSDocumentOption option, IPipelineWriter writer, ShouldProcess shouldProcess) { var rootedPath = PSDocumentOption.GetRootedPath(option.Output.Path); var filePath = !string.IsNullOrEmpty(result.Culture) && option.Output?.Culture?.Length > 1 ? Path.Combine(rootedPath, result.Culture, result.Name) : Path.Combine(rootedPath, result.Name); var parentPath = Directory.GetParent(filePath); if (!parentPath.Exists && shouldProcess(target: parentPath.FullName, action: PSDocsResources.ShouldCreatePath)) { Directory.CreateDirectory(path: parentPath.FullName); } if (shouldProcess(target: rootedPath, action: PSDocsResources.ShouldWriteFile)) { var encoding = GetEncoding(option.Markdown.Encoding.Value); File.WriteAllText(filePath, result.ToString(), encoding); // Write file info instead var fileInfo = new FileInfo(filePath); writer.WriteObject(fileInfo, false); } }
private static void WriteToFile(IDocumentResult result, PSDocumentOption option, IPipelineWriter writer, ShouldProcess shouldProcess) { // Calculate paths var fileName = string.Concat(result.InstanceName, result.Extension); var outputPath = PSDocumentOption.GetRootedPath(result.OutputPath); var filePath = Path.Combine(outputPath, fileName); var parentPath = Directory.GetParent(filePath); if (!parentPath.Exists && shouldProcess(target: parentPath.FullName, action: PSDocsResources.ShouldCreatePath)) { Directory.CreateDirectory(path: parentPath.FullName); } if (shouldProcess(target: outputPath, action: PSDocsResources.ShouldWriteFile)) { var encoding = GetEncoding(option.Markdown.Encoding.Value); File.WriteAllText(filePath, result.ToString(), encoding); // Write file info instead var fileInfo = new FileInfo(filePath); writer.WriteObject(fileInfo, false); } }
public virtual void UseCommandRuntime(PSCmdlet commandRuntime) { CmdletContext = commandRuntime; _ShouldProcess = commandRuntime.ShouldProcess; _Output.UseCommandRuntime(commandRuntime); }