Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 27 additions & 13 deletions Sources/Container-Compose/Commands/ComposeDown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,25 +44,39 @@ public struct ComposeDown: AsyncParsableCommand {
private var cwd: String { process.cwd ?? FileManager.default.currentDirectoryPath }

@Option(name: [.customShort("f"), .customLong("file")], help: "The path to your Docker Compose file")
var composeFilename: String = "compose.yml"
private var composePath: String { "\(cwd)/\(composeFilename)" } // Path to compose.yml
var composeFilename: String? = nil
private var composePath: String {
let filename = composeFilename ?? "compose.yml"
// Handle absolute paths
if filename.hasPrefix("/") || filename.hasPrefix("~") {
return filename
Comment thread
rtoohil marked this conversation as resolved.
Outdated
} else {
return "\(cwd)/\(filename)"
}
}

private var fileManager: FileManager { FileManager.default }
private var projectName: String?

public mutating func run() async throws {

// Check for supported filenames and extensions
let filenames = [
"compose.yml",
"compose.yaml",
"docker-compose.yml",
"docker-compose.yaml",
]
for filename in filenames {
if fileManager.fileExists(atPath: "\(cwd)/\(filename)") {
composeFilename = filename
break
// Check for supported filenames and extensions only if user didn't specify -f
if composeFilename == nil {
let filenames = [
"compose.yml",
"compose.yaml",
"docker-compose.yml",
"docker-compose.yaml",
]
for filename in filenames {
if fileManager.fileExists(atPath: "\(cwd)/\(filename)") {
composeFilename = filename
break
}
}
// If no file was found, default to compose.yml (will fail later with proper error)
if composeFilename == nil {
composeFilename = "compose.yml"
}
Copy link

Copilot AI Dec 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fallback assignment is redundant since line 49 already handles the nil case with composeFilename ?? \"compose.yml\". The composePath computed property will always default to "compose.yml" if composeFilename is nil, making this assignment unnecessary.

Suggested change
if composeFilename == nil {
composeFilename = "compose.yml"
}
// No need to assign composeFilename = "compose.yml" here; composePath already handles the nil case.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot is correct. this final if composeFilename == nil { is unnecessary. Please delete the if statement and do not leave the comment that copilot is suggesting.

}

Expand Down
40 changes: 27 additions & 13 deletions Sources/Container-Compose/Commands/ComposeUp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,16 @@ public struct ComposeUp: AsyncParsableCommand, @unchecked Sendable {
var detatch: Bool = false

@Option(name: [.customShort("f"), .customLong("file")], help: "The path to your Docker Compose file")
var composeFilename: String = "compose.yml"
private var composePath: String { "\(cwd)/\(composeFilename)" } // Path to compose.yml
var composeFilename: String? = nil
private var composePath: String {
let filename = composeFilename ?? "compose.yml"
// Handle absolute paths
if filename.hasPrefix("/") || filename.hasPrefix("~") {
return filename
Comment thread
rtoohil marked this conversation as resolved.
Outdated
} else {
return "\(cwd)/\(filename)"
}
}

@Flag(name: [.customShort("b"), .customLong("build")])
var rebuild: Bool = false
Expand Down Expand Up @@ -75,17 +83,23 @@ public struct ComposeUp: AsyncParsableCommand, @unchecked Sendable {
]

public mutating func run() async throws {
// Check for supported filenames and extensions
let filenames = [
"compose.yml",
"compose.yaml",
"docker-compose.yml",
"docker-compose.yaml",
]
for filename in filenames {
if fileManager.fileExists(atPath: "\(cwd)/\(filename)") {
composeFilename = filename
break
// Check for supported filenames and extensions only if user didn't specify -f
if composeFilename == nil {
Comment thread
rtoohil marked this conversation as resolved.
let filenames = [
"compose.yml",
"compose.yaml",
"docker-compose.yml",
"docker-compose.yaml",
]
for filename in filenames {
if fileManager.fileExists(atPath: "\(cwd)/\(filename)") {
composeFilename = filename
break
}
}
// If no file was found, default to compose.yml (will fail later with proper error)
if composeFilename == nil {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was correct. this final if composeFilename == nil { is unnecessary. Please delete the if statement and do not leave the comment that copilot is suggesting.

composeFilename = "compose.yml"
Comment thread
rtoohil marked this conversation as resolved.
Outdated
}
}

Expand Down