Files
swift-hpa/Sources/hpa/Internal/CommandConfigurationExtensions.swift
Michael Housh faa28749bc
All checks were successful
CI / Run Tests (push) Successful in 2m43s
feat: Merges dev
2024-12-17 15:55:36 -05:00

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()
}
}
}