File tree Expand file tree Collapse file tree
main/java/net/jbock/model
test/java/net/jbock/model Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -58,6 +58,24 @@ public static final class Builder {
5858 private Builder () {
5959 }
6060
61+ public Builder withOptions (List <Option > newOptions ) {
62+ options .clear ();
63+ options .addAll (newOptions );
64+ return this ;
65+ }
66+
67+ public Builder withParameters (List <Parameter > newParameters ) {
68+ parameters .clear ();
69+ parameters .addAll (newParameters );
70+ return this ;
71+ }
72+
73+ public Builder withDescriptionLines (List <String > newDescriptionLines ) {
74+ descriptionLines .clear ();
75+ descriptionLines .addAll (newDescriptionLines );
76+ return this ;
77+ }
78+
6179 /**
6280 * Sets the description key.
6381 *
@@ -140,6 +158,16 @@ public CommandModel build() {
140158 }
141159 }
142160
161+ public Builder toBuilder () {
162+ return builder ()
163+ .withDescriptionKey (descriptionKey )
164+ .withDescriptionLines (descriptionLines )
165+ .withProgramName (programName )
166+ .withSuperCommand (superCommand )
167+ .withOptions (options )
168+ .withParameters (parameters );
169+ }
170+
143171 /**
144172 * Returns the description key from the {@link Command#descriptionKey()} attribute,
145173 * possibly an empty string.
Original file line number Diff line number Diff line change 1+ package net .jbock .model ;
2+
3+ import org .junit .jupiter .api .Test ;
4+
5+ import java .util .List ;
6+
7+ import static org .junit .jupiter .api .Assertions .assertEquals ;
8+
9+ class CommandModelTest {
10+
11+ @ Test
12+ void testToBuilder () {
13+ Option option1 = Option .nullary ().withParamLabel ("v" ).withNames (List .of ("-v" )).build ();
14+ Option option2 = Option .nullary ().withParamLabel ("p" ).withNames (List .of ("-p" )).build ();
15+ CommandModel model1 = CommandModel .builder ()
16+ .addOption (option1 )
17+ .addOption (option2 )
18+ .build ();
19+ assertEquals (2 , model1 .options ().size ());
20+ CommandModel model2 = model1 .toBuilder ().withOptions (List .of (option1 )).build ();
21+ assertEquals (1 , model2 .options ().size ());
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments