Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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
6 changes: 3 additions & 3 deletions Sources/Container-Compose/Commands/ComposeDown.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ 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?
@OptionGroup
var composeFileOptions: ComposeFileOptions

private static let supportedComposeFilenames = [
"compose.yml",
Expand All @@ -58,7 +58,7 @@ public struct ComposeDown: AsyncParsableCommand {
}

private var composePath: String {
if let composeFilename {
if let composeFilename = composeFileOptions.composeFilename {
return resolvedPath(for: composeFilename, relativeTo: cwdURL)
}

Expand Down
22 changes: 22 additions & 0 deletions Sources/Container-Compose/Commands/ComposeFileOptions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//===----------------------------------------------------------------------===//
// Copyright © 2025 Morris Richman and the Container-Compose project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//

import ArgumentParser

public struct ComposeFileOptions: ParsableArguments, Sendable {
@Option(name: [.customShort("f"), .customLong("file")], help: "The path to your Docker Compose file")
public var composeFilename: String?
}
8 changes: 4 additions & 4 deletions Sources/Container-Compose/Commands/ComposeUp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public struct ComposeUp: AsyncParsableCommand, @unchecked Sendable {
help: "Detaches from container logs. Note: If you do NOT detach, killing this process will NOT kill the container. To kill the container, run container-compose down")
var detach: Bool = false

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

private static let supportedComposeFilenames = [
"compose.yml",
Expand All @@ -61,7 +61,7 @@ public struct ComposeUp: AsyncParsableCommand, @unchecked Sendable {
}

private var composePath: String {
if let composeFilename {
if let composeFilename = composeFileOptions.composeFilename {
return resolvedPath(for: composeFilename, relativeTo: cwdURL)
}

Expand Down Expand Up @@ -524,7 +524,7 @@ public struct ComposeUp: AsyncParsableCommand, @unchecked Sendable {
runCommandArgs.append(networkToConnect)
}
print(
"Info: Service '\(serviceName)' is configured to connect to networks: \(serviceNetworks.joined(separator: ", ")) ascertained from networks attribute in \(composeFilename)."
"Info: Service '\(serviceName)' is configured to connect to networks: \(serviceNetworks.joined(separator: ", ")) ascertained from networks attribute in \(composePath)."

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.

Double check the change on this variable name

)
print(
"Note: This tool assumes custom networks are defined at the top-level 'networks' key or are pre-existing. This tool does not create implicit networks for services if not explicitly defined at the top-level."
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
//===----------------------------------------------------------------------===//
// Copyright © 2025 Morris Richman and the Container-Compose project authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//===----------------------------------------------------------------------===//

import Testing
@testable import ContainerComposeCore

@Suite("Compose command parsing")
struct ComposeCommandParsingTests {

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.

These tests are kinda useless. However, check if calling "-f", "up" on the main entry point command is valid.

@Test("ComposeUp command accepts -f flag for compose file")
func composeUpCommandAcceptsFileFlag() throws {
let cmd = try ComposeUp.parse(["-f", "my-compose.yaml"])
#expect(cmd.composeFileOptions.composeFilename == "my-compose.yaml")
}

@Test("ComposeDown command accepts -f flag for compose file")
func composeDownCommandAcceptsFileFlag() throws {
let cmd = try ComposeDown.parse(["-f", "my-compose.yaml"])
#expect(cmd.composeFileOptions.composeFilename == "my-compose.yaml")
}
}
Loading