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

devonfw / IDEasy / 11497084978

24 Oct 2024 10:04AM UTC coverage: 66.811% (+0.008%) from 66.803%
11497084978

push

github

web-flow
simplify FlagProperty usage and allow ToolCommandlets to have long options (#644)

2403 of 3942 branches covered (60.96%)

Branch coverage included in aggregate %.

6267 of 9035 relevant lines covered (69.36%)

3.05 hits per line

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

87.5
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
  /**
19
   * The constructor.
20
   *
21
   * @param args the {@link CliArgument#of(String...) command line arguments}.
22
   */
23
  public CliArguments(String... args) {
24

25
    this(CliArgument.of(args));
4✔
26
  }
1✔
27

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

35
    this(arg, false, true);
5✔
36
  }
1✔
37

38
  CliArguments(CliArgument arg, boolean endOpts, boolean splitShortOpts) {
39

40
    super();
2✔
41
    this.initialArgument = arg;
3✔
42
    this.endOptions = endOpts;
3✔
43
    this.splitShortOpts = splitShortOpts;
3✔
44
    setCurrent(arg);
3✔
45
  }
1✔
46

47
  /**
48
   * Marks the end of the options so no further {@link CliArgument#getNext(boolean) option splitting} will be performed.
49
   *
50
   * @see #stopSplitShortOptions()
51
   */
52
  public void endOptions() {
53

54
    this.endOptions = true;
3✔
55
    this.splitShortOpts = false;
3✔
56
  }
1✔
57

58
  /**
59
   * Stops splitting of short options.
60
   *
61
   * @see CliArgument#getNext(boolean)
62
   * @see #endOptions()
63
   */
64
  public void stopSplitShortOptions() {
65

66
    this.splitShortOpts = false;
3✔
67
  }
1✔
68

69
  /**
70
   * @return {@code true} if the options have ended, {@code false} otherwise.
71
   * @see CliArgument#isEndOptions()
72
   * @see com.devonfw.tools.ide.property.Property#isEndOptions()
73
   * @see #endOptions()
74
   */
75
  public boolean isEndOptions() {
76

77
    return this.endOptions;
3✔
78
  }
79

80
  private void setCurrent(CliArgument arg) {
81

82
    if (arg.isEndOptions()) {
3!
83
      endOptions();
×
84
      this.currentArg = arg.getNext();
×
85
    } else {
86
      this.currentArg = arg;
3✔
87
    }
88
  }
1✔
89

90
  /**
91
   * @return the initial {@link CliArgument}.
92
   */
93
  public CliArgument getInitialArgument() {
94

95
    return this.initialArgument;
×
96
  }
97

98
  /**
99
   * @return the current {@link CliArgument}.
100
   * @see #hasNext()
101
   * @see #next()
102
   */
103
  public CliArgument current() {
104

105
    return this.currentArg;
3✔
106
  }
107

108
  @Override
109
  public boolean hasNext() {
110

111
    if (this.currentArg.isEnd()) {
4✔
112
      return false;
2✔
113
    }
114
    return !this.currentArg.next.isEnd();
9✔
115
  }
116

117
  /**
118
   * Consumes the {@link #current() current argument} and proceeds to the next one.
119
   *
120
   * @return the next {@link CliArgument}.
121
   */
122
  @Override
123
  public CliArgument next() {
124

125
    if (!this.currentArg.isEnd()) {
4!
126
      setCurrent(this.currentArg.getNext(this.splitShortOpts));
7✔
127
    }
128
    return this.currentArg;
3✔
129
  }
130

131
  /**
132
   * @return a copy of this {@link CliArguments} to fork a CLI matching of auto-completion.
133
   */
134
  public CliArguments copy() {
135

136
    return new CliArguments(this.currentArg, this.endOptions, this.splitShortOpts);
10✔
137
  }
138

139
  @Override
140
  public String toString() {
141

142
    return this.currentArg.getArgs();
4✔
143
  }
144

145
  /**
146
   * @param args the {@link CliArgument#of(String...) command line arguments}.
147
   * @return the {@link CliArguments}.
148
   */
149
  public static CliArguments ofCompletion(String... args) {
150

151
    return new CliArguments(CliArgument.ofCompletion(args));
6✔
152
  }
153

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

© 2025 Coveralls, Inc