feat: Working on node builder
This commit is contained in:
16
Sources/CliDoc/ArgumentParserExtensions/Abstract.swift
Normal file
16
Sources/CliDoc/ArgumentParserExtensions/Abstract.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
/// Use the `NodeBuilder` for generating an abstract.
|
||||
public struct Abstract: NodeRepresentable {
|
||||
@usableFromInline
|
||||
let label: any NodeRepresentable
|
||||
|
||||
@inlinable
|
||||
public init(@NodeBuilder label: () -> any NodeRepresentable) {
|
||||
self.label = label()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func render() -> String {
|
||||
label.render()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import ArgumentParser
|
||||
|
||||
public extension CommandConfiguration {
|
||||
|
||||
init(
|
||||
commandName: String? = nil,
|
||||
abstract: Abstract,
|
||||
usage: String? = nil,
|
||||
discussion: Discussion,
|
||||
version: String = "",
|
||||
shouldDisplay: Bool = true,
|
||||
subcommands: [any ParsableCommand.Type] = [],
|
||||
groupedSubcommands: [CommandGroup] = [],
|
||||
defaultSubcommand: ParsableCommand.Type? = nil,
|
||||
helpNames: NameSpecification? = nil,
|
||||
aliases: [String] = []
|
||||
) {
|
||||
self.init(
|
||||
commandName: commandName,
|
||||
abstract: abstract.render(),
|
||||
usage: usage,
|
||||
discussion: discussion.render(),
|
||||
version: version,
|
||||
shouldDisplay: shouldDisplay,
|
||||
subcommands: subcommands,
|
||||
groupedSubcommands: groupedSubcommands,
|
||||
defaultSubcommand: defaultSubcommand,
|
||||
helpNames: helpNames,
|
||||
aliases: aliases
|
||||
)
|
||||
}
|
||||
}
|
||||
16
Sources/CliDoc/ArgumentParserExtensions/Discussion.swift
Normal file
16
Sources/CliDoc/ArgumentParserExtensions/Discussion.swift
Normal file
@@ -0,0 +1,16 @@
|
||||
/// Use the `NodeBuilder` for generating a discussion.
|
||||
public struct Discussion: NodeRepresentable {
|
||||
@usableFromInline
|
||||
let label: any NodeRepresentable
|
||||
|
||||
@inlinable
|
||||
public init(@NodeBuilder label: () -> any NodeRepresentable) {
|
||||
self.label = label()
|
||||
}
|
||||
|
||||
@inlinable
|
||||
public func render() -> String {
|
||||
label.render()
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user