11package de .donnerbart .split ;
22
3+ import com .beust .jcommander .IDefaultProvider ;
34import com .beust .jcommander .IStringConverter ;
45import com .beust .jcommander .Parameter ;
6+ import com .beust .jcommander .converters .PathConverter ;
57import org .jetbrains .annotations .NotNull ;
68import org .jetbrains .annotations .Nullable ;
79
810import java .nio .file .Path ;
9- import java .nio .file .Paths ;
1011import java .util .Arrays ;
11- import java .util .Objects ;
1212
1313class Arguments {
1414
@@ -54,7 +54,8 @@ class Arguments {
5454 @ NotNull NewTestTimeOption newTestTimeOption = NewTestTimeOption .AVERAGE ;
5555
5656 @ 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 )
5859 @ SuppressWarnings ("NotNullFieldNotInitialized" )
5960 @ NotNull Path workingDirectory ;
6061
@@ -69,12 +70,6 @@ class Arguments {
6970 @ Parameter (names = {"--debug" , "-d" }, description = "Enables debug logging." )
7071 boolean debug = false ;
7172
72- void init () {
73- workingDirectory = Objects .requireNonNullElse (workingDirectory , Paths .get (System .getProperty ("user.dir" )))
74- .toAbsolutePath ()
75- .normalize ();
76- }
77-
7873 public static class FormatOptionConverter implements IStringConverter <FormatOption > {
7974
8075 @ Override
@@ -96,4 +91,27 @@ public static class NewTestTimeOptionConverter implements IStringConverter<NewTe
9691 .orElseThrow ();
9792 }
9893 }
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+ }
99117}
0 commit comments