@@ -19,10 +19,10 @@ object OptParser extends OptionParser[Config]("decaf") {
19
19
.text(" input Decaf source" )
20
20
.action { case (f, config) => config.copy(source = f) }
21
21
.validate { f =>
22
- if (! f.isFile ) {
23
- Left (" not a file " )
24
- } else if (! f.exists ) {
25
- Left (" not exist " )
22
+ if (! f.exists ) {
23
+ Left (" not exist: " + f )
24
+ } else if (! f.isFile ) {
25
+ Left (" not a file: " + f )
26
26
} else {
27
27
Right ()
28
28
}
@@ -33,10 +33,8 @@ object OptParser extends OptionParser[Config]("decaf") {
33
33
.text(" output file for result, available except PA5 (default stdout)" )
34
34
.action { case (o, config) => config.copy(output = new FileOutputStream (o)) }
35
35
.validate { f =>
36
- if (! f.isFile) {
37
- Left (" not a file" )
38
- } else if (! f.getParentFile.exists) {
39
- Left (" directory not exist" )
36
+ if (f.getParentFile != null && ! f.getParentFile.exists) {
37
+ Left (" parent directory not exist: " + f.getParentFile)
40
38
} else {
41
39
Right ()
42
40
}
@@ -47,10 +45,10 @@ object OptParser extends OptionParser[Config]("decaf") {
47
45
.text(" output directory for low-level code, available >= PA3 (default .)" )
48
46
.action { case (d, config) => config.copy(dstDir = d) }
49
47
.validate { d =>
50
- if (! d.isDirectory ) {
51
- Left (" not a directory " )
52
- } else if (! d.exists ) {
53
- Left (" not exist " )
48
+ if (! d.exists ) {
49
+ Left (" not exist: " + d )
50
+ } else if (! d.isDirectory ) {
51
+ Left (" not a directory: " + d )
54
52
} else {
55
53
Right ()
56
54
}
@@ -74,6 +72,13 @@ object OptParser extends OptionParser[Config]("decaf") {
74
72
.valueName(" file" )
75
73
.text(" also dump log to a file" )
76
74
.action { case (f, config) => config.copy(logFile = f) }
75
+ .validate { f =>
76
+ if (f.getParentFile != null && ! f.getParentFile.exists) {
77
+ Left (" parent directory not exist: " + f.getParentFile)
78
+ } else {
79
+ Right ()
80
+ }
81
+ }
77
82
78
83
help('h' , " help" )
79
84
.text(" prints this usage text\n " )
0 commit comments