feat: Adds extension to argument parser's command configuration
This commit is contained in:
36
Sources/CliDoc/CommandConfiguration+TextNode.swift
Normal file
36
Sources/CliDoc/CommandConfiguration+TextNode.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
import ArgumentParser
|
||||
|
||||
public extension CommandConfiguration {
|
||||
|
||||
/// Generate a new command configuration, using ``TextNode``'s for the abstract,
|
||||
/// usage, and discussion parameters.
|
||||
///
|
||||
///
|
||||
init<A: TextNode, U: TextNode, D: TextNode>(
|
||||
commandName: String? = nil,
|
||||
abstract: Abstract<A>,
|
||||
usage: Usage<U>,
|
||||
discussion: Discussion<D>,
|
||||
version: String = "",
|
||||
shouldDisplay: Bool = true,
|
||||
subcommands ungroupedSubcommands: [ParsableCommand.Type] = [],
|
||||
groupedSubcommands: [CommandGroup] = [],
|
||||
defaultSubcommand: ParsableCommand.Type? = nil,
|
||||
helpNames: NameSpecification? = nil,
|
||||
aliases: [String] = []
|
||||
) {
|
||||
self.init(
|
||||
commandName: commandName,
|
||||
abstract: abstract.render(),
|
||||
usage: usage.render(),
|
||||
discussion: discussion.render(),
|
||||
version: version,
|
||||
shouldDisplay: shouldDisplay,
|
||||
subcommands: ungroupedSubcommands,
|
||||
groupedSubcommands: groupedSubcommands,
|
||||
defaultSubcommand: defaultSubcommand,
|
||||
helpNames: helpNames,
|
||||
aliases: aliases
|
||||
)
|
||||
}
|
||||
}
|
||||
14
Sources/CliDoc/Nodes/Abstract.swift
Normal file
14
Sources/CliDoc/Nodes/Abstract.swift
Normal file
@@ -0,0 +1,14 @@
|
||||
import CliDocCore
|
||||
|
||||
public struct Abstract<Content: TextNode>: TextNode {
|
||||
@usableFromInline
|
||||
let content: Content
|
||||
|
||||
public init(@TextBuilder content: () -> Content) {
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
public var body: some TextNode {
|
||||
content
|
||||
}
|
||||
}
|
||||
14
Sources/CliDoc/Nodes/Discussion.swift
Normal file
14
Sources/CliDoc/Nodes/Discussion.swift
Normal file
@@ -0,0 +1,14 @@
|
||||
import CliDocCore
|
||||
|
||||
public struct Discussion<Content: TextNode>: TextNode {
|
||||
@usableFromInline
|
||||
let content: Content
|
||||
|
||||
public init(@TextBuilder content: () -> Content) {
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
public var body: some TextNode {
|
||||
content
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import CliDocCore
|
||||
import Rainbow
|
||||
|
||||
// TODO: Use labeled content.
|
||||
public struct Note<Label: TextNode, Content: TextNode>: TextNode {
|
||||
@usableFromInline
|
||||
let label: Label
|
||||
|
||||
14
Sources/CliDoc/Nodes/Usage.swift
Normal file
14
Sources/CliDoc/Nodes/Usage.swift
Normal file
@@ -0,0 +1,14 @@
|
||||
import CliDocCore
|
||||
|
||||
public struct Usage<Content: TextNode>: TextNode {
|
||||
@usableFromInline
|
||||
let content: Content
|
||||
|
||||
public init(@TextBuilder content: () -> Content) {
|
||||
self.content = content()
|
||||
}
|
||||
|
||||
public var body: some TextNode {
|
||||
content
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user