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

devonfw / IDEasy / 26101908636

19 May 2026 01:55PM UTC coverage: 70.982% (+0.003%) from 70.979%
26101908636

Pull #1859

github

web-flow
Merge cf4a7f717 into b4eeee25f
Pull Request #1859: #1392: Smart completions

4472 of 6964 branches covered (64.22%)

Branch coverage included in aggregate %.

11521 of 15567 relevant lines covered (74.01%)

3.14 hits per line

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

69.64
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
  public CliArguments(int completionIdx, String... args) {
19
    this(CliArgument.of(completionIdx, args));
5✔
20
  }
1✔
21

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

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

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

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

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

44
    super();
2✔
45
    this.initialArgument = arg;
3✔
46
    this.endOptions = endOpts;
3✔
47
    this.splitShortOpts = splitShortOpts;
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;
×
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();
2✔
96
      this.currentArg = arg.getNext();
5✔
97
    } else {
98
      this.currentArg = arg;
3✔
99
    }
100
  }
1✔
101

102
  /**
103
   * @return {@code true} if the last argument shall be {@link CliArgument#isCompletion() completed}, {@code false}.
104
   */
105
  public boolean isCompletion() {
106

107
    CliArgument arg = this.currentArg;
×
108
    while ((arg != null) && !arg.isEnd()) {
×
109
      if (arg.isCompletion()) {
×
110
        return true;
×
111
      }
112
      arg = arg.next;
×
113
    }
114
    return false;
×
115
  }
116

117
  /**
118
   * @return the initial {@link CliArgument}.
119
   */
120
  public CliArgument getInitialArgument() {
121

122
    return this.initialArgument;
×
123
  }
124

125
  /**
126
   * @return the current {@link CliArgument}.
127
   * @see #hasNext()
128
   * @see #next()
129
   */
130
  public CliArgument current() {
131

132
    return this.currentArg;
3✔
133
  }
134

135
  @Override
136
  public boolean hasNext() {
137

138
    if (this.currentArg.isEnd()) {
4✔
139
      return false;
2✔
140
    }
141
    return !this.currentArg.next.isEnd();
9✔
142
  }
143

144
  /**
145
   * Consumes the {@link #current() current argument} and proceeds to the next one.
146
   *
147
   * @return the next {@link CliArgument}.
148
   */
149
  @Override
150
  public CliArgument next() {
151

152
    if (!this.currentArg.isEnd()) {
4!
153
      setCurrent(this.currentArg.getNext(this.splitShortOpts));
7✔
154
    }
155
    return this.currentArg;
3✔
156
  }
157

158
  /**
159
   * @return a copy of this {@link CliArguments} to fork a CLI matching of auto-completion.
160
   */
161
  public CliArguments copy() {
162

163
    return new CliArguments(this.currentArg, this.endOptions, this.splitShortOpts);
10✔
164
  }
165

166
  @Override
167
  public String toString() {
168

169
    return this.currentArg.getArgs();
4✔
170
  }
171

172
  public static CliArguments of(int completionIdx, String... args) {
173
    return new CliArguments(completionIdx, args);
6✔
174
  }
175

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

182
    return new CliArguments(CliArgument.ofCompletion(args));
6✔
183
  }
184

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