@@ -34,16 +34,29 @@ object Cli {
34
34
given ioContextShift as ContextShift [IO ] =
35
35
IO .contextShift(scala.concurrent.ExecutionContext .Implicits .global)
36
36
37
+ object Options {
38
+ enum RecordType (value : String ) {
39
+ case Example extends RecordType (" example" )
40
+ case PredictionLog extends RecordType (" prediction_log" )
41
+ }
42
+
43
+ given recordValueConverter as ValueConverter [RecordType ] =
44
+ singleArgConverter[RecordType ] { s =>
45
+ RecordType .valueOf(s.split(" _" ).fold(" " )(_ + _.capitalize))
46
+ }
47
+ }
48
+
37
49
final class Options (arguments : Seq [String ]) extends ScallopConf (arguments) {
50
+ import Options .{given _ , _ }
38
51
printedName = " tfr"
39
52
banner(""" Usage: tfr [options] <files? | STDIN>
40
53
|TensorFlow TFRecord reader CLI tool
41
54
|Options:
42
55
|""" .stripMargin)
43
56
44
- val record : ScallopOption [String ] =
45
- opt[String ](
46
- default = Some (" example " ),
57
+ val record : ScallopOption [RecordType ] =
58
+ opt[RecordType ](
59
+ default = Some (RecordType . Example ),
47
60
descr = " Record type to be read { example | prediction_log }"
48
61
)
49
62
val checkCrc32 = opt[Boolean ](
@@ -55,7 +68,7 @@ object Cli {
55
68
default = Some (false ),
56
69
descr = " Output examples as flat JSON objects"
57
70
)
58
- val files = trailArg[List [String ]](
71
+ val files = trailArg[List [String ]](
59
72
required = false ,
60
73
descr = " files? | STDIN" ,
61
74
default = Some (List .empty)
@@ -65,19 +78,18 @@ object Cli {
65
78
66
79
def main (args : Array [String ]): Unit = {
67
80
val options = Options (ArraySeq .unsafeWrapArray(args))
68
- println(options.files())
69
81
val resources = options.files() match
70
82
case Nil => Resources .stdin[IO ] :: Nil
71
83
case l => l.iterator.map(Resources .file[IO ]).toList
72
84
73
85
options.record() match
74
- case " example " =>
86
+ case Options . RecordType . Example =>
75
87
given exampleEncoder as Encoder [Example ] =
76
88
if options.flat() then flat.exampleEncoder
77
89
else tfr.instances.example.exampleEncoder
78
90
79
91
run[Example ](options, resources)
80
- case " prediction_log " =>
92
+ case Options . RecordType . PredictionLog =>
81
93
given predictionLogEncoder as Encoder [PredictionLog ] =
82
94
tfr.instances.prediction.predictionLogEncoder
83
95
0 commit comments