62 lines
1.3 KiB
Swift
62 lines
1.3 KiB
Swift
import ArgumentParser
|
|
import CliDoc
|
|
import Rainbow
|
|
|
|
extension CommandConfiguration {
|
|
|
|
static func playbook(
|
|
commandName: String,
|
|
abstract: String,
|
|
parentCommand: String? = nil,
|
|
examples: Example...
|
|
) -> Self {
|
|
.init(
|
|
commandName: commandName,
|
|
abstract: Abstract { abstract.blue },
|
|
usage: Usage.default(commandName: commandName, parentCommand: parentCommand),
|
|
discussion: Discussion.playbook(examples: examples)
|
|
)
|
|
}
|
|
}
|
|
|
|
func createAbstract(_ string: String) -> String {
|
|
"\(string.blue)"
|
|
}
|
|
|
|
extension Usage where Content == AnyTextNode {
|
|
|
|
static func `default`(
|
|
commandName: String,
|
|
parentCommand: String?,
|
|
usesArguments: Bool = true,
|
|
usesOptions: Bool = true,
|
|
usesExtraArguments: Bool = true
|
|
) -> Self {
|
|
.init {
|
|
HStack {
|
|
HStack {
|
|
"\(Constants.appName)"
|
|
if let parentCommand {
|
|
parentCommand
|
|
}
|
|
commandName
|
|
}
|
|
.color(.blue).bold()
|
|
|
|
if usesOptions {
|
|
"[OPTIONS]".color(.green)
|
|
}
|
|
if usesArguments {
|
|
"[ARGUMENTS]".color(.cyan)
|
|
}
|
|
if usesExtraArguments {
|
|
"--"
|
|
"[EXTRA-OPTIONS]".color(.magenta)
|
|
}
|
|
}
|
|
|
|
.eraseToAnyTextNode()
|
|
}
|
|
}
|
|
}
|