feat: Working encrypt and decrypt commands.

This commit is contained in:
2024-11-30 19:27:18 -05:00
parent 81925a95d6
commit 56a406b231
7 changed files with 87 additions and 26 deletions

View File

@@ -3,6 +3,19 @@ import Rainbow
extension CommandConfiguration {
static func create(
commandName: String,
abstract: String,
usesExtraArgs: Bool = true,
discussion: Discussion
) -> Self {
.init(
commandName: commandName,
abstract: createAbstract(abstract),
discussion: discussion.render()
)
}
static func create(
commandName: String,
abstract: String,
@@ -25,12 +38,12 @@ extension CommandConfiguration {
.create(
commandName: commandName,
abstract: abstract,
discussion: [.note(label: "Most options are not required if you have a configuration file setup.")]
+ examples.nodes(parentCommand)
+ [
.seeAlso(label: "Ansible playbook options.", command: "ansible-playbook"),
.important(label: Constants.importantExtraArgsNote)
]
discussion: .default(
usesExtraArgs: true,
parentCommand: parentCommand,
examples: examples,
seeAlso: .seeAlso(label: "Ansible playbook options.", command: "ansible-playbook")
)
)
}
}
@@ -42,6 +55,21 @@ func createAbstract(_ string: String) -> String {
struct Discussion {
let nodes: [Node]
static func `default`(
usesExtraArgs: Bool,
parentCommand: String?,
examples: [(label: String, example: String)],
seeAlso: Node?
) -> Self {
var nodes = Array.defaultNodes + examples.nodes(parentCommand)
if let seeAlso { nodes.append(seeAlso) }
if usesExtraArgs && examples.count > 0 { nodes.append(.important(label: Constants.importantExtraArgsNote)) }
return .init(
nodes: nodes,
usesExtraArgs: usesExtraArgs
)
}
init(usesExtraArgs: Bool = true, _ nodes: Node...) {
self.init(nodes: nodes, usesExtraArgs: usesExtraArgs)
}
@@ -225,9 +253,13 @@ private extension Array where Element == (label: String, example: String) {
}
}
private extension Array where Element == Node {
extension Array where Element == Node {
func render(separator: String = "\n\n") -> String {
static var defaultNodes: Self {
[.note(label: "Most options are not required if you have a configuration file setup.")]
}
fileprivate func render(separator: String = "\n\n") -> String {
map {
// Strip of any new-line characters from the last section of the rendered string
// of the node. This allows us to have a consistent single new-line between each