60 lines
1.4 KiB
Swift
60 lines
1.4 KiB
Swift
import ArgumentParser
|
|
import CliClient
|
|
import VaultClient
|
|
|
|
// Holds the common options for vault commands, as they all share the
|
|
// same structure.
|
|
@dynamicMemberLookup
|
|
struct VaultOptions: ParsableArguments {
|
|
|
|
@OptionGroup var globals: BasicGlobalOptions
|
|
|
|
@Option(
|
|
name: .shortAndLong,
|
|
help: "The vault file path.",
|
|
completion: .file()
|
|
)
|
|
var file: String?
|
|
|
|
@Argument(
|
|
help: "Extra arguments to pass to the vault command."
|
|
)
|
|
var extraOptions: [String] = []
|
|
|
|
subscript<T>(dynamicMember keyPath: WritableKeyPath<BasicGlobalOptions, T>) -> T {
|
|
get { globals[keyPath: keyPath] }
|
|
set { globals[keyPath: keyPath] = newValue }
|
|
}
|
|
|
|
subscript<T>(dynamicMember keyPath: KeyPath<BasicGlobalOptions, T>) -> T {
|
|
globals[keyPath: keyPath]
|
|
}
|
|
|
|
}
|
|
|
|
extension VaultOptions {
|
|
func loggingOptions(commandName: String) -> CliClient.LoggingOptions {
|
|
globals.loggingOptions(commandName: commandName)
|
|
}
|
|
}
|
|
|
|
extension VaultOptions {
|
|
|
|
func runOptions(
|
|
commandName: String,
|
|
outputFilePath: String? = nil
|
|
) -> VaultClient.RunOptions {
|
|
.init(
|
|
extraOptions: extraOptions,
|
|
loggingOptions: .init(
|
|
commandName: commandName,
|
|
logLevel: .init(globals: globals, quietOnlyPlaybook: false)
|
|
),
|
|
outputFilePath: outputFilePath,
|
|
quiet: globals.quiet,
|
|
shell: globals.shell,
|
|
vaultFilePath: file
|
|
)
|
|
}
|
|
}
|