Skip to content

Commit e618857

Browse files
committed
Improvements
1 parent 645301b commit e618857

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+401
-72
lines changed

Plugins/container-compose/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// swift-tools-version: 6.2
22
//===----------------------------------------------------------------------===//
3-
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
3+
// Copyright © 2025 Mazdak Rezvani and contributors. All rights reserved.
44
//
55
// Licensed under the Apache License, Version 2.0 (the "License");
66
// you may not use this file except in compliance with the License.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//===----------------------------------------------------------------------===//
2-
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
2+
// Copyright © 2025 Mazdak Rezvani and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//===----------------------------------------------------------------------===//
2-
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
2+
// Copyright © 2025 Mazdak Rezvani and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -69,6 +69,8 @@ struct ComposeDown: AsyncParsableCommand {
6969

7070
// Create orchestrator
7171
let orchestrator = Orchestrator(log: log)
72+
// Allow Ctrl-C to stop the command cleanly
73+
installDefaultTerminationHandlers()
7274

7375
// Stop services
7476
let result = try await orchestrator.down(

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//===----------------------------------------------------------------------===//
2-
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
2+
// Copyright © 2025 Mazdak Rezvani and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -71,9 +71,14 @@ struct ComposeExec: AsyncParsableCommand {
7171
composeFile: composeFile,
7272
projectName: composeOptions.getProjectName(),
7373
profiles: composeOptions.profile,
74-
selectedServices: []
74+
selectedServices: [service]
7575
)
7676

77+
// Early validation and helpful messaging
78+
guard project.services.keys.contains(service) else {
79+
throw ValidationError("Service '\(service)' not found or not enabled by active profiles")
80+
}
81+
7782
// Create orchestrator
7883
let orchestrator = Orchestrator(log: log)
7984

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//===----------------------------------------------------------------------===//
2-
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
2+
// Copyright © 2025 Mazdak Rezvani and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -59,6 +59,7 @@ struct ComposeHealth: AsyncParsableCommand {
5959

6060
// Create orchestrator
6161
let orchestrator = Orchestrator(log: log)
62+
installDefaultTerminationHandlers()
6263

6364
// Check health
6465
let healthStatus = try await orchestrator.checkHealth(

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

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//===----------------------------------------------------------------------===//
2-
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
2+
// Copyright © 2025 Mazdak Rezvani and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -40,6 +40,12 @@ struct ComposeLogs: AsyncParsableCommand {
4040

4141
@Flag(name: [.customLong("timestamps"), .customShort("t")], help: "Show timestamps")
4242
var timestamps: Bool = false
43+
44+
@Flag(name: .long, help: "Disable log prefixes (container-name |)")
45+
var noLogPrefix: Bool = false
46+
47+
@Flag(name: .long, help: "Disable colored output")
48+
var noColor: Bool = false
4349

4450
@Argument(help: "Services to display logs for")
4551
var services: [String] = []
@@ -64,6 +70,8 @@ struct ComposeLogs: AsyncParsableCommand {
6470

6571
// Create orchestrator
6672
let orchestrator = Orchestrator(log: log)
73+
// Install Ctrl-C handler to exit gracefully while following logs
74+
installDefaultTerminationHandlers()
6775

6876
// Get logs stream
6977
let logStream = try await orchestrator.logs(
@@ -73,19 +81,26 @@ struct ComposeLogs: AsyncParsableCommand {
7381
tail: tail,
7482
timestamps: timestamps
7583
)
76-
77-
// Print logs with service names and optional timestamps
84+
85+
// Compute padding width for aligned prefixes
86+
let nameWidth = noLogPrefix ? nil : try await TargetsUtil.computePrefixWidth(project: project, services: services)
87+
88+
// Print logs with container-name prefixes and optional timestamps
7889
let dateFormatter = DateFormatter()
7990
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss.SSS"
8091

8192
for try await entry in logStream {
82-
var output = "[\(entry.serviceName)]"
83-
93+
var output = ""
94+
if !noLogPrefix {
95+
output += LogPrefixFormatter.coloredPrefix(for: entry.containerName, width: nameWidth, colorEnabled: !noColor)
96+
}
8497
if timestamps {
85-
output += " \(dateFormatter.string(from: entry.timestamp))"
98+
// If no prefix, don't double space
99+
if !output.isEmpty { output += " " }
100+
output += dateFormatter.string(from: entry.timestamp)
86101
}
87-
88-
output += " \(entry.message)"
102+
if !output.isEmpty { output += " " }
103+
output += entry.message
89104

90105
switch entry.stream {
91106
case .stdout:

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//===----------------------------------------------------------------------===//
2-
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
2+
// Copyright © 2025 Mazdak Rezvani and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -58,6 +58,7 @@ struct ComposePS: AsyncParsableCommand {
5858

5959
// Create orchestrator
6060
let orchestrator = Orchestrator(log: log)
61+
installDefaultTerminationHandlers()
6162

6263
// Get service statuses
6364
let statuses = try await orchestrator.ps(project: project)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//===----------------------------------------------------------------------===//
2-
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
2+
// Copyright © 2025 Mazdak Rezvani and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.

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

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//===----------------------------------------------------------------------===//
2-
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
2+
// Copyright © 2025 Mazdak Rezvani and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -51,11 +51,36 @@ struct ComposeRestart: AsyncParsableCommand {
5151
let project = try converter.convert(
5252
composeFile: composeFile,
5353
projectName: composeOptions.getProjectName(),
54-
profiles: composeOptions.profile
54+
profiles: composeOptions.profile,
55+
selectedServices: services
5556
)
5657

58+
// Warn about requested services excluded by profiles or not present
59+
if !services.isEmpty {
60+
let requested = Set(services)
61+
let resolved = Set(project.services.keys)
62+
let missing = requested.subtracting(resolved)
63+
if !missing.isEmpty {
64+
let prof = composeOptions.profile
65+
let profStr = prof.isEmpty ? "(none)" : prof.joined(separator: ",")
66+
FileHandle.standardError.write(Data("compose: warning: skipping services not enabled by active profiles or not found: \(missing.sorted().joined(separator: ",")) (profiles=\(profStr))\n".utf8))
67+
}
68+
}
69+
70+
// Early exit if nothing to restart
71+
if project.services.isEmpty {
72+
let prof = composeOptions.profile
73+
let profStr = prof.isEmpty ? "(none)" : prof.joined(separator: ",")
74+
print("No services matched the provided filters. Nothing to restart.")
75+
print("- Project: \(project.name)")
76+
if !services.isEmpty { print("- Services filter: \(services.joined(separator: ","))") }
77+
print("- Profiles: \(profStr)")
78+
return
79+
}
80+
5781
// Create orchestrator
5882
let orchestrator = Orchestrator(log: log)
83+
installDefaultTerminationHandlers()
5984

6085
// Create progress bar
6186
let progressConfig = try ProgressConfig(

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//===----------------------------------------------------------------------===//
2-
// Copyright © 2025 Apple Inc. and the container project authors. All rights reserved.
2+
// Copyright © 2025 Mazdak Rezvani and contributors. All rights reserved.
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
@@ -69,6 +69,7 @@ struct ComposeRm: AsyncParsableCommand {
6969

7070
// Create orchestrator
7171
let orchestrator = Orchestrator(log: log)
72+
installDefaultTerminationHandlers()
7273

7374
// Remove containers
7475
let result = try await orchestrator.remove(
@@ -89,4 +90,4 @@ struct ComposeRm: AsyncParsableCommand {
8990
}
9091
}
9192
}
92-
}
93+
}

0 commit comments

Comments
 (0)