• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

devonfw / IDEasy / 28679309219

03 Jul 2026 07:14PM UTC coverage: 71.37% (-0.01%) from 71.381%
28679309219

push

github

web-flow
#2044: hacky fix for endoption token (#2055)

Co-authored-by: Jörg Hohwiller <hohwille@users.noreply.github.com>

4717 of 7308 branches covered (64.55%)

Branch coverage included in aggregate %.

12132 of 16300 relevant lines covered (74.43%)

3.15 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.77
cli/src/main/java/com/devonfw/tools/ide/cli/CliArguments.java
1
package com.devonfw.tools.ide.cli;
2

3
import java.util.Iterator;
4

5
/**
6
 * Wraps {@link CliArgument} as state object allowing to consume arguments.
7
 */
8
public class CliArguments implements Iterator<CliArgument> {
9

10
  private final CliArgument initialArgument;
11

12
  private CliArgument currentArg;
13

14
  private boolean endOptions;
15

16
  private boolean splitShortOpts;
17

18
  /** If true, do not discard the special end-of-options token "--" but keep it as current argument. */
19
  private boolean preserveEndOptionsToken;
20

21
  /**
22
   * The constructor.
23
   *
24
   * @param args the {@link CliArgument#of(String...) command line arguments}.
25
   */
26
  public CliArguments(String... args) {
27

28
    this(CliArgument.of(args));
4✔
29
  }
1✔
30

31
  /**
32
   * The constructor.
33
   *
34
   * @param arg the {@link #current() initial} {@link CliArgument}.
35
   */
36
  public CliArguments(CliArgument arg) {
37

38
    this(arg, false, true);
5✔
39
  }
1✔
40

41
  CliArguments(CliArgument arg, boolean endOpts, boolean splitShortOpts) {
42

43
    super();
2✔
44
    this.initialArgument = arg;
3✔
45
    this.endOptions = endOpts;
3✔
46
    this.splitShortOpts = splitShortOpts;
3✔
47
    this.preserveEndOptionsToken = false;
3✔
48
    setCurrent(arg);
3✔
49
  }
1✔
50

51
  CliArguments(CliArgument arg, boolean endOpts, boolean splitShortOpts, boolean preserveEndOptionsToken) {
52

53
    super();
2✔
54
    this.initialArgument = arg;
3✔
55
    this.endOptions = endOpts;
3✔
56
    this.splitShortOpts = splitShortOpts;
3✔
57
    this.preserveEndOptionsToken = preserveEndOptionsToken;
3✔
58
    setCurrent(arg);
3✔
59
  }
1✔
60

61
  /**
62
   * Marks the end of the options so no further {@link CliArgument#getNext(boolean) option splitting} will be performed.
63
   *
64
   * @see #stopSplitShortOptions()
65
   */
66
  public void endOptions() {
67

68
    this.endOptions = true;
3✔
69
    this.splitShortOpts = false;
3✔
70
  }
1✔
71

72
  /**
73
   * Stops splitting of short options.
74
   *
75
   * @see CliArgument#getNext(boolean)
76
   * @see #endOptions()
77
   */
78
  public void stopSplitShortOptions() {
79

80
    this.splitShortOpts = false;
×
81
  }
×
82

83
  /**
84
   * @return {@code true} if short options (e.g. "-bdf") should not be split (e.g. into "-b -d -f" for "--batch --debug --force"), {@code false} otherwise.
85
   */
86
  public boolean isSplitShortOpts() {
87

88
    return splitShortOpts;
3✔
89
  }
90

91
  /**
92
   * @return {@code true} if the options have ended, {@code false} otherwise.
93
   * @see CliArgument#isEndOptions()
94
   * @see com.devonfw.tools.ide.property.Property#isEndOptions()
95
   * @see #endOptions()
96
   */
97
  public boolean isEndOptions() {
98

99
    return this.endOptions;
3✔
100
  }
101

102
  private void setCurrent(CliArgument arg) {
103

104
    if (arg.isEndOptions()) {
3!
105
      endOptions();
×
106
      if (this.preserveEndOptionsToken) {
×
107
        this.currentArg = arg;
×
108
      } else {
109
        this.currentArg = arg.getNext();
×
110
      }
111
    } else {
112
      this.currentArg = arg;
3✔
113
    }
114
  }
1✔
115

116
  /**
117
   * @return {@code true} if the last argument shall be {@link CliArgument#isCompletion() completed}, {@code false}.
118
   */
119
  public boolean isCompletion() {
120

121
    CliArgument arg = this.currentArg;
×
122
    while ((arg != null) && !arg.isEnd()) {
×
123
      if (arg.isCompletion()) {
×
124
        return true;
×
125
      }
126
      arg = arg.next;
×
127
    }
128
    return false;
×
129
  }
130

131
  /**
132
   * @return the initial {@link CliArgument}.
133
   */
134
  public CliArgument getInitialArgument() {
135

136
    return this.initialArgument;
×
137
  }
138

139
  /**
140
   * @return the current {@link CliArgument}.
141
   * @see #hasNext()
142
   * @see #next()
143
   */
144
  public CliArgument current() {
145

146
    return this.currentArg;
3✔
147
  }
148

149
  @Override
150
  public boolean hasNext() {
151

152
    if (this.currentArg.isEnd()) {
4✔
153
      return false;
2✔
154
    }
155
    return !this.currentArg.next.isEnd();
9✔
156
  }
157

158
  /**
159
   * Consumes the {@link #current() current argument} and proceeds to the next one.
160
   *
161
   * @return the next {@link CliArgument}.
162
   */
163
  @Override
164
  public CliArgument next() {
165

166
    if (!this.currentArg.isEnd()) {
4!
167
      setCurrent(this.currentArg.getNext(this.splitShortOpts));
7✔
168
    }
169
    return this.currentArg;
3✔
170
  }
171

172
  /**
173
   * @return a copy of this {@link CliArguments} to fork a CLI matching of auto-completion.
174
   */
175
  public CliArguments copy() {
176
    return new CliArguments(this.currentArg, this.endOptions, this.splitShortOpts, this.preserveEndOptionsToken);
12✔
177
  }
178

179
  @Override
180
  public String toString() {
181

182
    return this.currentArg.getArgs();
4✔
183
  }
184

185
  /**
186
   * @param args the {@link CliArgument#of(String...) command line arguments}.
187
   * @return the {@link CliArguments}.
188
   */
189
  public static CliArguments ofCompletion(String... args) {
190

191
    CliArguments ca = new CliArguments(CliArgument.ofCompletion(args));
6✔
192
    ca.preserveEndOptionsToken = true;
3✔
193
    return ca;
2✔
194
  }
195

196
  /**
197
   * Enable preserving the literal end-of-options token "--" so it is not consumed by the parser. This is used for completion mode where the user input should
198
   * be preserved verbatim.
199
   */
200
  public void preserveEndOptionsToken() {
201
    this.preserveEndOptionsToken = true;
×
202
  }
×
203

204
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc