File tree Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Expand file tree Collapse file tree 2 files changed +29
-8
lines changed Original file line number Diff line number Diff line change 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
+ */
7
10
8
11
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
+ }
Original file line number Diff line number Diff line change @@ -13,10 +13,21 @@ import Glibc
13
13
srandom ( UInt32 ( clock ( ) ) )
14
14
#endif
15
15
16
+ import Foundation
16
17
import DeckOfPlayingCards
17
18
import ArgumentParser
18
19
20
+ var stdout = FileHandle . standardOutput
21
+ var stderr = FileHandle . standardError
22
+
19
23
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
+
20
31
@Argument ( help: " The number of cards to deal. " )
21
32
var count : UInt = 10
22
33
@@ -26,11 +37,11 @@ struct Deal: ParsableCommand {
26
37
27
38
for _ in 0 ..< count {
28
39
guard let card = deck. deal ( ) else {
29
- print ( " No More Cards! " )
40
+ print ( " No more cards " , to : & stderr )
30
41
break
31
42
}
32
43
33
- print ( card)
44
+ print ( card, to : & stdout )
34
45
}
35
46
}
36
47
}
You can’t perform that action at this time.
0 commit comments