File tree Expand file tree Collapse file tree 4 files changed +25
-17
lines changed
Examples/echo-metadata/Sources/Subcommands Expand file tree Collapse file tree 4 files changed +25
-17
lines changed Original file line number Diff line number Diff line change @@ -43,11 +43,15 @@ struct Collect: AsyncParsableCommand {
43
43
try await writer. write ( . with { $0. text = String ( part) } )
44
44
}
45
45
} onResponse: { response in
46
- print (
47
- " collect ← initial metadata: \( response . metadata . filter ( { $0 . key . starts ( with : " echo- " ) } ) ) "
48
- )
46
+ let initialMetadata = Metadata ( response . metadata . filter ( { $0 . key . starts ( with : " echo- " ) } ) )
47
+ print ( " collect ← initial metadata: \( initialMetadata ) " )
48
+
49
49
print ( " collect ← message: \( try response. message. text) " )
50
- print ( " collect ← trailing metadata: \( response. trailingMetadata) " )
50
+
51
+ let trailingMetadata = Metadata (
52
+ response. trailingMetadata. filter ( { $0. key. starts ( with: " echo- " ) } )
53
+ )
54
+ print ( " collect ← trailing metadata: \( trailingMetadata) " )
51
55
}
52
56
}
53
57
}
Original file line number Diff line number Diff line change @@ -43,18 +43,20 @@ struct Expand: AsyncParsableCommand {
43
43
try await echo. expand ( message, metadata: requestMetadata) { response in
44
44
let responseContents = try response. accepted. get ( )
45
45
46
- print (
47
- " expand ← initial metadata: \( Metadata ( responseContents. metadata. filter ( { $0. key. starts ( with: " echo- " ) } ) ) ) "
46
+ let initialMetadata = Metadata (
47
+ responseContents. metadata. filter ( { $0. key. starts ( with: " echo- " ) } )
48
48
)
49
+ print ( " expand ← initial metadata: \( initialMetadata) " )
49
50
for try await part in responseContents. bodyParts {
50
51
switch part {
51
52
case . message( let message) :
52
53
print ( " expand ← message: \( message. text) " )
53
54
54
55
case . trailingMetadata( let trailingMetadata) :
55
- print (
56
- " expand ← trailing metadata: \( Metadata ( trailingMetadata. filter ( { $0. key. starts ( with: " echo- " ) } ) ) ) "
56
+ let trailingMetadata = Metadata (
57
+ trailingMetadata. filter ( { $0. key. starts ( with: " echo- " ) } )
57
58
)
59
+ print ( " expand ← trailing metadata: \( trailingMetadata) " )
58
60
}
59
61
}
60
62
}
Original file line number Diff line number Diff line change @@ -40,13 +40,13 @@ struct Get: AsyncParsableCommand {
40
40
print ( " get → metadata: \( requestMetadata) " )
41
41
print ( " get → message: \( message. text) " )
42
42
try await echo. get ( message, metadata: requestMetadata) { response in
43
- print (
44
- " get ← initial metadata: \( Metadata ( response. metadata. filter ( { $0. key. starts ( with: " echo- " ) } ) ) ) "
45
- )
43
+ let initialMetadata = Metadata ( response. metadata. filter ( { $0. key. starts ( with: " echo- " ) } ) )
44
+ print ( " get ← initial metadata: \( initialMetadata) " )
46
45
print ( " get ← message: \( try response. message. text) " )
47
- print (
48
- " get ← trailing metadata: \( Metadata ( response. trailingMetadata. filter ( { $0. key. starts ( with: " echo- " ) } ) ) ) "
46
+ let trailingMetadata = Metadata (
47
+ response. trailingMetadata. filter ( { $0. key. starts ( with: " echo- " ) } )
49
48
)
49
+ print ( " get ← trailing metadata: \( trailingMetadata) " )
50
50
}
51
51
}
52
52
}
Original file line number Diff line number Diff line change @@ -45,18 +45,20 @@ struct Update: AsyncParsableCommand {
45
45
} onResponse: { response in
46
46
let responseContents = try response. accepted. get ( )
47
47
48
- print (
49
- " update ← initial metadata: \( Metadata ( responseContents. metadata. filter ( { $0. key. starts ( with: " echo- " ) } ) ) ) "
48
+ let initialMetadata = Metadata (
49
+ responseContents. metadata. filter ( { $0. key. starts ( with: " echo- " ) } )
50
50
)
51
+ print ( " update ← initial metadata: \( initialMetadata) " )
51
52
for try await part in responseContents. bodyParts {
52
53
switch part {
53
54
case . message( let message) :
54
55
print ( " update ← message: \( message. text) " )
55
56
56
57
case . trailingMetadata( let trailingMetadata) :
57
- print (
58
- " update ← trailing metadata: \( Metadata ( trailingMetadata. filter ( { $0. key. starts ( with: " echo- " ) } ) ) ) "
58
+ let trailingMetadata = Metadata (
59
+ trailingMetadata. filter ( { $0. key. starts ( with: " echo- " ) } )
59
60
)
61
+ print ( " update ← trailing metadata: \( trailingMetadata) " )
60
62
}
61
63
}
62
64
}
You can’t perform that action at this time.
0 commit comments