feat: Adds command documentation about piping to other commands.

This commit is contained in:
2024-12-16 12:41:49 -05:00
parent 1429c51821
commit 8c402f3f5f
2 changed files with 22 additions and 3 deletions

View File

@@ -26,14 +26,33 @@ extension Array where Element == Example {
))
return output
}
func addingPipeToOtherCommand(command: String) -> Self {
var output = self
output.append((
label: "Piping output to other command.",
example: "\(command) --quiet | xargs open"
))
return output
}
}
extension ExampleSection where Header == String, Label == String {
static func `default`(examples: [Example], usesPassingExtraOptions: Bool = true) -> some TextNode {
static func `default`(
examples: [Example],
usesPassingExtraOptions: Bool = true,
usesPipeToOtherCommand: Bool = true
) -> some TextNode {
var examples = examples
if usesPassingExtraOptions, let first = examples.first {
if let first = examples.first {
if usesPassingExtraOptions {
examples = examples.addingPassingOptions(command: first.example)
}
if usesPipeToOtherCommand {
examples = examples.addingPipeToOtherCommand(command: first.example)
}
}
return Self(examples: examples) {
"EXAMPLES:"
} label: {