1
1
package de .donnerbart .split ;
2
2
3
+ import com .beust .jcommander .IDefaultProvider ;
3
4
import com .beust .jcommander .IStringConverter ;
4
5
import com .beust .jcommander .Parameter ;
6
+ import com .beust .jcommander .converters .PathConverter ;
5
7
import org .jetbrains .annotations .NotNull ;
6
8
import org .jetbrains .annotations .Nullable ;
7
9
8
10
import java .nio .file .Path ;
9
- import java .nio .file .Paths ;
10
11
import java .util .Arrays ;
11
- import java .util .Objects ;
12
12
13
13
class Arguments {
14
14
@@ -54,7 +54,8 @@ class Arguments {
54
54
@ NotNull NewTestTimeOption newTestTimeOption = NewTestTimeOption .AVERAGE ;
55
55
56
56
@ Parameter (names = {"--working-directory" , "-w" },
57
- description = "The working directory. Defaults to the current directory." )
57
+ description = "The working directory. Defaults to the current directory." ,
58
+ converter = WorkingDirectoryOptionConverter .class )
58
59
@ SuppressWarnings ("NotNullFieldNotInitialized" )
59
60
@ NotNull Path workingDirectory ;
60
61
@@ -69,12 +70,6 @@ class Arguments {
69
70
@ Parameter (names = {"--debug" , "-d" }, description = "Enables debug logging." )
70
71
boolean debug = false ;
71
72
72
- void init () {
73
- workingDirectory = Objects .requireNonNullElse (workingDirectory , Paths .get (System .getProperty ("user.dir" )))
74
- .toAbsolutePath ()
75
- .normalize ();
76
- }
77
-
78
73
public static class FormatOptionConverter implements IStringConverter <FormatOption > {
79
74
80
75
@ Override
@@ -96,4 +91,27 @@ public static class NewTestTimeOptionConverter implements IStringConverter<NewTe
96
91
.orElseThrow ();
97
92
}
98
93
}
94
+
95
+ public static class WorkingDirectoryOptionConverter extends PathConverter {
96
+
97
+ public WorkingDirectoryOptionConverter (final @ NotNull String optionName ) {
98
+ super (optionName );
99
+ }
100
+
101
+ @ Override
102
+ public @ NotNull Path convert (final @ NotNull String value ) {
103
+ return super .convert (value ).toAbsolutePath ().normalize ();
104
+ }
105
+ }
106
+
107
+ public static class DefaultProvider implements IDefaultProvider {
108
+
109
+ @ Override
110
+ public @ Nullable String getDefaultValueFor (final @ NotNull String optionName ) {
111
+ if (optionName .equals ("--working-directory" )) {
112
+ return System .getProperty ("user.dir" );
113
+ }
114
+ return null ;
115
+ }
116
+ }
99
117
}
0 commit comments