-
-
Notifications
You must be signed in to change notification settings - Fork 23
Properly handle the -f flag to be the primary file when used by up or down #36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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 | ||||||||||
| } 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" | ||||||||||
| } | ||||||||||
|
||||||||||
| if composeFilename == nil { | |
| composeFilename = "compose.yml" | |
| } | |
| // No need to assign composeFilename = "compose.yml" here; composePath already handles the nil case. |
There was a problem hiding this comment.
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
rtoohil marked this conversation as resolved.
Outdated
|
||
| } else { | ||
| return "\(cwd)/\(filename)" | ||
| } | ||
| } | ||
|
|
||
| @Flag(name: [.customShort("b"), .customLong("build")]) | ||
| var rebuild: Bool = false | ||
|
|
@@ -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 { | ||
|
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 { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copilot was correct. this final |
||
| composeFilename = "compose.yml" | ||
|
rtoohil marked this conversation as resolved.
Outdated
|
||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.