Skip to content

Commit 92b3f99

Browse files
committed
Add command abstract and description
Print 'No more cards' to standard error
1 parent 2df0a9a commit 92b3f99

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed
Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
//
2-
// File.swift
3-
// File
4-
//
5-
// Created by Mattt Zmuda on 8/18/21.
6-
//
1+
/*
2+
This source file is part of the Swift.org open source project
3+
4+
Copyright 2021 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See http://swift.org/LICENSE.txt for license information
8+
See http://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
*/
710

811
import Foundation
12+
13+
extension FileHandle: TextOutputStream {
14+
public func write(_ string: String) {
15+
guard let data = string.data(using: .utf8) else { return }
16+
write(data)
17+
}
18+
}

Sources/Dealer/main.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,21 @@ import Glibc
1313
srandom(UInt32(clock()))
1414
#endif
1515

16+
import Foundation
1617
import DeckOfPlayingCards
1718
import ArgumentParser
1819

20+
var stdout = FileHandle.standardOutput
21+
var stderr = FileHandle.standardError
22+
1923
struct Deal: ParsableCommand {
24+
static var configuration = CommandConfiguration(
25+
abstract: "Shuffles a deck of playing cards and deals a number of cards.",
26+
discussion: """
27+
Prints each card to stdout until the deck is completely dealt,
28+
and prints "No more cards" to stderr if there are no cards remaining.
29+
""")
30+
2031
@Argument(help: "The number of cards to deal.")
2132
var count: UInt = 10
2233

@@ -26,11 +37,11 @@ struct Deal: ParsableCommand {
2637

2738
for _ in 0..<count {
2839
guard let card = deck.deal() else {
29-
print("No More Cards!")
40+
print("No more cards", to: &stderr)
3041
break
3142
}
3243

33-
print(card)
44+
print(card, to: &stdout)
3445
}
3546
}
3647
}

0 commit comments

Comments
 (0)