Skip to content

Commit 7466a97

Browse files
committed
Updated API to account for changes in #603
1 parent 341a5da commit 7466a97

18 files changed

+181
-163
lines changed

Plugins/container-compose/Package.resolved

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Plugins/container-compose/Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let package = Package(
2626
],
2727
dependencies: [
2828
.package(name: "container", path: "../.."), // Main container package
29-
.package(url: "https://github.com/apple/containerization.git", exact: "0.6.2"),
29+
.package(url: "https://github.com/apple/containerization.git", exact: "0.8.0"),
3030
.package(url: "https://github.com/jpsim/Yams.git", from: "5.0.0"),
3131
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.3.0"),
3232
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
@@ -56,6 +56,7 @@ let package = Package(
5656
.product(name: "ContainerizationOS", package: "containerization"),
5757
.product(name: "ArgumentParser", package: "swift-argument-parser"),
5858
.product(name: "ContainerClient", package: "container"),
59+
.product(name: "ContainerCommands", package: "container"),
5960
],
6061
path: "Sources/Core"
6162
),

Plugins/container-compose/Sources/CLI/ComposeDown.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct ComposeDown: AsyncParsableCommand {
3131
var composeOptions: ComposeOptions
3232

3333
@OptionGroup
34-
var global: Flags.Global
34+
var global: ComposeGlobalOptions
3535

3636
@Flag(name: .long, help: "Remove named volumes declared in the volumes section")
3737
var volumes: Bool = false
@@ -40,6 +40,7 @@ struct ComposeDown: AsyncParsableCommand {
4040
var removeOrphans: Bool = false
4141

4242
func run() async throws {
43+
global.configureLogging()
4344
// Set environment variables
4445
composeOptions.loadDotEnvIfPresent()
4546
composeOptions.setEnvironmentVariables()

Plugins/container-compose/Sources/CLI/ComposeExec.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct ComposeExec: AsyncParsableCommand {
3030
var composeOptions: ComposeOptions
3131

3232
@OptionGroup
33-
var global: Flags.Global
33+
var global: ComposeGlobalOptions
3434

3535
@Flag(name: [.customLong("detach"), .customShort("d")], help: "Run command in the background")
3636
var detach: Bool = false
@@ -57,6 +57,7 @@ struct ComposeExec: AsyncParsableCommand {
5757
var command: [String] = []
5858

5959
func run() async throws {
60+
global.configureLogging()
6061
// Load .env and set environment variables
6162
composeOptions.loadDotEnvIfPresent()
6263
composeOptions.setEnvironmentVariables()

Plugins/container-compose/Sources/CLI/ComposeHealth.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct ComposeHealth: AsyncParsableCommand {
3232

3333
@OptionGroup var composeOptions: ComposeOptions
3434

35-
@OptionGroup var global: Flags.Global
35+
@OptionGroup var global: ComposeGlobalOptions
3636

3737
@Argument(help: "Services to check (omit to check all)")
3838
var services: [String] = []
@@ -41,6 +41,7 @@ struct ComposeHealth: AsyncParsableCommand {
4141
var quiet: Bool = false
4242

4343
func run() async throws {
44+
global.configureLogging()
4445

4546
// Set environment variables
4647
composeOptions.setEnvironmentVariables()

Plugins/container-compose/Sources/CLI/ComposeLogs.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct ComposeLogs: AsyncParsableCommand {
3030
var composeOptions: ComposeOptions
3131

3232
@OptionGroup
33-
var global: Flags.Global
33+
var global: ComposeGlobalOptions
3434

3535
@Flag(name: .long, help: "Follow log output")
3636
var follow: Bool = false
@@ -54,6 +54,7 @@ struct ComposeLogs: AsyncParsableCommand {
5454
var services: [String] = []
5555

5656
func run() async throws {
57+
global.configureLogging()
5758
// Load .env and set environment variables
5859
composeOptions.loadDotEnvIfPresent()
5960
composeOptions.setEnvironmentVariables()

Plugins/container-compose/Sources/CLI/ComposePS.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct ComposePS: AsyncParsableCommand {
3030
var composeOptions: ComposeOptions
3131

3232
@OptionGroup
33-
var global: Flags.Global
33+
var global: ComposeGlobalOptions
3434

3535
@Flag(name: [.customLong("all"), .customShort("a")], help: "Show all containers (default shows just running)")
3636
var all: Bool = false
@@ -39,6 +39,7 @@ struct ComposePS: AsyncParsableCommand {
3939
var quiet: Bool = false
4040

4141
func run() async throws {
42+
global.configureLogging()
4243
// Load .env and set environment variables
4344
composeOptions.loadDotEnvIfPresent()
4445
composeOptions.setEnvironmentVariables()

Plugins/container-compose/Sources/CLI/ComposePlugin.swift

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,24 @@ import Foundation
2020
import ContainerLog
2121
import Logging
2222

23-
// Import Flags namespace from main container CLI
24-
struct Flags {
25-
struct Global: ParsableArguments {
26-
@Flag(name: .shortAndLong, help: "Enable debug logging")
27-
var debug = false
23+
struct ComposeGlobalOptions: ParsableArguments {
24+
@OptionGroup
25+
var shared: Flags.Global
2826

29-
@Flag(name: .long, help: "Allow YAML anchors and merge keys in compose files")
30-
var allowAnchors = false
27+
@Flag(name: .long, help: "Allow YAML anchors and merge keys in compose files")
28+
var allowAnchors = false
29+
30+
var debug: Bool {
31+
shared.debug
32+
}
33+
34+
func configureLogging() {
35+
let debugEnvVar = ProcessInfo.processInfo.environment["CONTAINER_DEBUG"]
36+
if debug || debugEnvVar != nil {
37+
log.logLevel = .debug
38+
} else {
39+
log.logLevel = .info
40+
}
3141
}
3242
}
3343

Plugins/container-compose/Sources/CLI/ComposeRestart.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct ComposeRestart: AsyncParsableCommand {
3030
var composeOptions: ComposeOptions
3131

3232
@OptionGroup
33-
var global: Flags.Global
33+
var global: ComposeGlobalOptions
3434

3535
@Option(name: [.customLong("timeout"), .customShort("t")], help: "Specify a shutdown timeout in seconds (default: 10)")
3636
var timeout: Int = 10
@@ -42,6 +42,7 @@ struct ComposeRestart: AsyncParsableCommand {
4242
var noHealthcheck: Bool = false
4343

4444
func run() async throws {
45+
global.configureLogging()
4546
// Set environment variables
4647
composeOptions.setEnvironmentVariables()
4748

Plugins/container-compose/Sources/CLI/ComposeRm.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct ComposeRm: AsyncParsableCommand {
3131
var composeOptions: ComposeOptions
3232

3333
@OptionGroup
34-
var global: Flags.Global
34+
var global: ComposeGlobalOptions
3535

3636
@Flag(name: .long, help: "Force removal of running containers")
3737
var force: Bool = false
@@ -40,6 +40,7 @@ struct ComposeRm: AsyncParsableCommand {
4040
var services: [String] = []
4141

4242
func run() async throws {
43+
global.configureLogging()
4344
// Set environment variables
4445
composeOptions.loadDotEnvIfPresent()
4546
composeOptions.setEnvironmentVariables()

0 commit comments

Comments
 (0)