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

devonfw / IDEasy / 27826212370

19 Jun 2026 12:39PM UTC coverage: 71.36% (-0.02%) from 71.381%
27826212370

Pull #2055

github

web-flow
Merge a54ab4723 into 3a08f1d5c
Pull Request #2055: #2044: hacky fix for endoption token

4705 of 7290 branches covered (64.54%)

Branch coverage included in aggregate %.

12121 of 16289 relevant lines covered (74.41%)

3.15 hits per line

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

60.94
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
  /**
52
   * Marks the end of the options so no further {@link CliArgument#getNext(boolean) option splitting} will be performed.
53
   *
54
   * @see #stopSplitShortOptions()
55
   */
56
  public void endOptions() {
57

58
    this.endOptions = true;
3✔
59
    this.splitShortOpts = false;
3✔
60
  }
1✔
61

62
  /**
63
   * Stops splitting of short options.
64
   *
65
   * @see CliArgument#getNext(boolean)
66
   * @see #endOptions()
67
   */
68
  public void stopSplitShortOptions() {
69

70
    this.splitShortOpts = false;
×
71
  }
×
72

73
  /**
74
   * @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.
75
   */
76
  public boolean isSplitShortOpts() {
77

78
    return splitShortOpts;
3✔
79
  }
80

81
  /**
82
   * @return {@code true} if the options have ended, {@code false} otherwise.
83
   * @see CliArgument#isEndOptions()
84
   * @see com.devonfw.tools.ide.property.Property#isEndOptions()
85
   * @see #endOptions()
86
   */
87
  public boolean isEndOptions() {
88

89
    return this.endOptions;
3✔
90
  }
91

92
  private void setCurrent(CliArgument arg) {
93

94
    if (arg.isEndOptions()) {
3!
95
      endOptions();
×
96
      if (this.preserveEndOptionsToken) {
×
97
        this.currentArg = arg;
×
98
      } else {
99
        this.currentArg = arg.getNext();
×
100
      }
101
    } else {
102
      this.currentArg = arg;
3✔
103
    }
104
  }
1✔
105

106
  /**
107
   * @return {@code true} if the last argument shall be {@link CliArgument#isCompletion() completed}, {@code false}.
108
   */
109
  public boolean isCompletion() {
110

111
    CliArgument arg = this.currentArg;
×
112
    while ((arg != null) && !arg.isEnd()) {
×
113
      if (arg.isCompletion()) {
×
114
        return true;
×
115
      }
116
      arg = arg.next;
×
117
    }
118
    return false;
×
119
  }
120

121
  /**
122
   * @return the initial {@link CliArgument}.
123
   */
124
  public CliArgument getInitialArgument() {
125

126
    return this.initialArgument;
×
127
  }
128

129
  /**
130
   * @return the current {@link CliArgument}.
131
   * @see #hasNext()
132
   * @see #next()
133
   */
134
  public CliArgument current() {
135

136
    return this.currentArg;
3✔
137
  }
138

139
  @Override
140
  public boolean hasNext() {
141

142
    if (this.currentArg.isEnd()) {
4✔
143
      return false;
2✔
144
    }
145
    return !this.currentArg.next.isEnd();
9✔
146
  }
147

148
  /**
149
   * Consumes the {@link #current() current argument} and proceeds to the next one.
150
   *
151
   * @return the next {@link CliArgument}.
152
   */
153
  @Override
154
  public CliArgument next() {
155

156
    if (!this.currentArg.isEnd()) {
4!
157
      setCurrent(this.currentArg.getNext(this.splitShortOpts));
7✔
158
    }
159
    return this.currentArg;
3✔
160
  }
161

162
  /**
163
   * @return a copy of this {@link CliArguments} to fork a CLI matching of auto-completion.
164
   */
165
  public CliArguments copy() {
166

167
    CliArguments copy = new CliArguments(this.currentArg, this.endOptions, this.splitShortOpts);
10✔
168
    copy.preserveEndOptionsToken = this.preserveEndOptionsToken;
4✔
169
    return copy;
2✔
170
  }
171

172
  @Override
173
  public String toString() {
174

175
    return this.currentArg.getArgs();
4✔
176
  }
177

178
  /**
179
   * @param args the {@link CliArgument#of(String...) command line arguments}.
180
   * @return the {@link CliArguments}.
181
   */
182
  public static CliArguments ofCompletion(String... args) {
183

184
    CliArguments ca = new CliArguments(CliArgument.ofCompletion(args));
6✔
185
    ca.preserveEndOptionsToken = true;
3✔
186
    return ca;
2✔
187
  }
188

189
  /**
190
   * 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
191
   * be preserved verbatim.
192
   */
193
  public void preserveEndOptionsToken() {
194
    this.preserveEndOptionsToken = true;
×
195
  }
×
196

197
}
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