Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion Sources/Container-Compose/Commands/ComposeBuild.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public struct ComposeBuild: AsyncParsableCommand, @unchecked Sendable {
@OptionGroup
var logging: Flags.Logging

private var cwd: String { process.cwd ?? FileManager.default.currentDirectoryPath }
private var cwd: String { composeFileOptions.effectiveCwd(processCwd: process.cwd) }

private var cwdURL: URL { URL(fileURLWithPath: cwd) }

Expand Down
2 changes: 1 addition & 1 deletion Sources/Container-Compose/Commands/ComposeDown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public struct ComposeDown: AsyncParsableCommand {
@OptionGroup
var process: Flags.Process

private var cwd: String { process.cwd ?? FileManager.default.currentDirectoryPath }
private var cwd: String { composeFileOptions.effectiveCwd(processCwd: process.cwd) }

@OptionGroup
var composeFileOptions: ComposeFileOptions
Expand Down
17 changes: 16 additions & 1 deletion Sources/Container-Compose/Commands/ComposeFileOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,25 @@
//===----------------------------------------------------------------------===//

import ArgumentParser
import Foundation

public struct ComposeFileOptions: ParsableArguments, Sendable {
public init() {}

@Option(name: [.customShort("f"), .customLong("file")], help: "The path to your Docker Compose file")
public var composeFilename: String?

@Option(name: .customLong("project-directory"), help: "Specify an alternate working directory")
public var projectDirectory: String?

/// Resolves the effective working directory with priority:
/// 1. `projectDirectory` (--project-directory flag)
/// 2. `processCwd` (from Flags.Process)
/// 3. `FileManager.default.currentDirectoryPath` (fallback)
public func effectiveCwd(processCwd: String?) -> String {
if let dir = projectDirectory {
return resolvedPath(for: dir, relativeTo: URL(fileURLWithPath: FileManager.default.currentDirectoryPath, isDirectory: true))
}
return processCwd ?? FileManager.default.currentDirectoryPath
}
}
2 changes: 1 addition & 1 deletion Sources/Container-Compose/Commands/ComposeUp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public struct ComposeUp: AsyncParsableCommand, @unchecked Sendable {
@OptionGroup
var logging: Flags.Logging

private var cwd: String { process.cwd ?? FileManager.default.currentDirectoryPath }
private var cwd: String { composeFileOptions.effectiveCwd(processCwd: process.cwd) }

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