Skip to content
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/Packages
/*.xcodeproj
Package.resolved
.swiftpm
10 changes: 0 additions & 10 deletions CONTRIBUTING.md

This file was deleted.

38 changes: 19 additions & 19 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// swift-tools-version:5.5
// The swift-tools-version declares the minimum version of Swift required to build this package.
// swift-tools-version:6.0

/*
This source file is part of the Swift.org open source project

Copyright 2015 – 2021 Apple Inc. and the Swift project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See http://swift.org/LICENSE.txt for license information
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
*/
//===----------------------------------------------------------------------===//
//
// This source file is part of the example package dealer open source project
//
// Copyright (c) 2015-2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

import PackageDescription

Expand All @@ -19,18 +19,18 @@ let package = Package(
.macOS(.v11)
],
products: [
.executable(name: "dealer", targets: ["dealer"]),
.executable(name: "dealer",
targets: ["dealer"]),
],
dependencies: [
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/apple/example-package-deckofplayingcards.git",
from: "3.0.0"),
.package(url: "https://github.com/apple/swift-argument-parser.git",
from: "0.4.4"),
.package(
url: "https://github.com/swiftlang/example-package-deckofplayingcards.git",
from: "4.0.0"),
.package(
url: "https://github.com/apple/swift-argument-parser.git",
from: "1.6.0"),
],
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.executableTarget(
name: "dealer",
dependencies: [
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Swift Example: Package Dealer

To build this example package:

git clone https://github.com/apple/example-package-dealer.git
cd example-package-dealer
swift run
swift run dealer <count>

For more information, visit [Swift's package manager documentation](https://www.swift.org/package-manager/).
67 changes: 0 additions & 67 deletions Sources/dealer/Deal.swift

This file was deleted.

74 changes: 74 additions & 0 deletions Sources/dealer/Dealer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the example package dealer open source project
//
// Copyright (c) 2015-2025 Apple Inc. and the Swift project authors
// Licensed under Apache License v2.0 with Runtime Library Exception
//
// See https://swift.org/LICENSE.txt for license information
//
//===----------------------------------------------------------------------===//

import ArgumentParser
import DeckOfPlayingCards
import Foundation
import PlayingCard

#if os(Linux)
import Glibc
#endif

@main
struct Dealer: ParsableCommand {
enum Error: Swift.Error, CustomStringConvertible {
case notEnoughCards

var description: String {
switch self {
case .notEnoughCards:
return "Not enough cards"
}
}
}

static let configuration = CommandConfiguration(
abstract: "Shuffles a deck of playing cards and deals a number of cards.",
discussion: """
For each count argument, prints a line of tab-delimited cards to stdout,
or if there aren't enough cards remaining,
prints "Not enough cards" to stderr and exits with a nonzero status.
""")

@Argument(
help: .init(
"The number of cards to deal at a time.",
valueName: "count"))
var counts: [UInt]

mutating func run() throws {
#if os(Linux)
srandom(UInt32(clock()))
#endif

var deck = Deck.standard52CardDeck()
deck.shuffle()

for count in counts {
var cards: [PlayingCard] = []

for _ in 0..<count {
guard let card = deck.deal() else {
Self.exit(withError: Error.notEnoughCards)
}

cards.append(card)
}

print(cards.map(\.description).joined(separator: "\t"))
}
}
}

// Empty class that provides a convenient handle to request
// the bundle that contains this code.
class BundleMarker {}
Loading