97 lines
2.1 KiB
Swift
97 lines
2.1 KiB
Swift
import ArgumentParser
|
|
import CommandClient
|
|
import ConfigurationClient
|
|
import PlaybookClient
|
|
|
|
struct BasicGlobalOptions: ParsableArguments {
|
|
@Flag(
|
|
name: .shortAndLong,
|
|
help: "Increase logging level (can be passed multiple times)."
|
|
)
|
|
var verbose: Int
|
|
|
|
@Flag(
|
|
name: .shortAndLong,
|
|
help: "Supress logging."
|
|
)
|
|
var quiet = false
|
|
|
|
@Option(
|
|
name: .shortAndLong,
|
|
help: "Optional shell to use when calling shell commands.",
|
|
completion: .file()
|
|
)
|
|
var shell: String?
|
|
|
|
}
|
|
|
|
@dynamicMemberLookup
|
|
struct GlobalOptions: ParsableArguments {
|
|
|
|
@Option(
|
|
name: .long,
|
|
help: "Optional path to the ansible hpa playbook directory."
|
|
)
|
|
var playbookDirectory: String?
|
|
|
|
@Option(
|
|
name: .shortAndLong,
|
|
help: "Optional path to the ansible inventory to use."
|
|
)
|
|
var inventoryPath: String?
|
|
|
|
@Flag(
|
|
name: .long,
|
|
help: "Supress only playbook logging."
|
|
)
|
|
var quietOnlyPlaybook = false
|
|
|
|
@OptionGroup var basic: BasicGlobalOptions
|
|
|
|
subscript<T>(dynamicMember keyPath: WritableKeyPath<BasicGlobalOptions, T>) -> T {
|
|
get { basic[keyPath: keyPath] }
|
|
set { basic[keyPath: keyPath] = newValue }
|
|
}
|
|
|
|
subscript<T>(dynamicMember keyPath: KeyPath<BasicGlobalOptions, T>) -> T {
|
|
basic[keyPath: keyPath]
|
|
}
|
|
|
|
}
|
|
|
|
extension GlobalOptions {
|
|
func loggingOptions(commandName: String) -> LoggingOptions {
|
|
.init(
|
|
commandName: commandName,
|
|
logLevel: .init(globals: basic, quietOnlyPlaybook: quietOnlyPlaybook)
|
|
)
|
|
}
|
|
}
|
|
|
|
extension BasicGlobalOptions {
|
|
func loggingOptions(commandName: String) -> LoggingOptions {
|
|
.init(
|
|
commandName: commandName,
|
|
logLevel: .init(globals: self, quietOnlyPlaybook: false)
|
|
)
|
|
}
|
|
}
|
|
|
|
extension GlobalOptions {
|
|
func sharedPlaybookRunOptions(
|
|
commandName: String,
|
|
extraOptions: [String]?
|
|
) -> PlaybookClient.RunPlaybook.SharedRunOptions {
|
|
return .init(
|
|
extraOptions: extraOptions,
|
|
inventoryFilePath: inventoryPath,
|
|
loggingOptions: .init(
|
|
commandName: commandName,
|
|
logLevel: .init(globals: basic, quietOnlyPlaybook: quietOnlyPlaybook)
|
|
),
|
|
quiet: basic.quiet,
|
|
shell: basic.shell
|
|
)
|
|
}
|
|
}
|