feat: Working encrypt and decrypt commands.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -5,7 +5,7 @@ extension Logger.Level {
|
||||
|
||||
/// Set the log level based on the user's options supplied.
|
||||
init(globals: BasicGlobalOptions, quietOnlyPlaybook: Bool) {
|
||||
if quietOnlyPlaybook || !globals.quiet {
|
||||
if !quietOnlyPlaybook && !globals.quiet {
|
||||
switch globals.verbose {
|
||||
case 0:
|
||||
self = .info
|
||||
@@ -16,6 +16,7 @@ extension Logger.Level {
|
||||
default:
|
||||
self = .info
|
||||
}
|
||||
return
|
||||
}
|
||||
self = .info
|
||||
}
|
||||
|
||||
@@ -26,16 +26,23 @@ func runVault(
|
||||
|
||||
let defaultArgs = configuration.defaultVaultArgs ?? []
|
||||
|
||||
var vaultArgs = ["ansible-vault"]
|
||||
+ args
|
||||
+ defaultArgs
|
||||
+ options.extraArgs
|
||||
+ [path]
|
||||
|
||||
if args.contains("encrypt"),
|
||||
!vaultArgs.contains("--encrypt-vault-id"),
|
||||
let id = configuration.defaultVaultEncryptId
|
||||
{
|
||||
vaultArgs.append(contentsOf: ["--encrypt-vault-id", id])
|
||||
}
|
||||
|
||||
try await cliClient.runCommand(
|
||||
quiet: options.quiet,
|
||||
shell: options.shellOrDefault,
|
||||
["ansible-vault"]
|
||||
+ args
|
||||
+ defaultArgs
|
||||
+ options.extraArgs
|
||||
+ [path]
|
||||
vaultArgs
|
||||
)
|
||||
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user