• 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

60.27
cli/src/main/java/com/devonfw/tools/ide/cli/Ideasy.java
1
package com.devonfw.tools.ide.cli;
2

3
import java.net.URLEncoder;
4
import java.nio.charset.StandardCharsets;
5

6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
8

9
import com.devonfw.tools.ide.commandlet.CompleteCommandlet;
10
import com.devonfw.tools.ide.commandlet.ContextCommandlet;
11
import com.devonfw.tools.ide.context.AbstractIdeContext;
12
import com.devonfw.tools.ide.context.IdeContext;
13
import com.devonfw.tools.ide.context.IdeContextConsole;
14
import com.devonfw.tools.ide.context.IdeStartContextImpl;
15
import com.devonfw.tools.ide.log.JulLogLevel;
16
import com.devonfw.tools.ide.property.FlagProperty;
17
import com.devonfw.tools.ide.property.Property;
18

19
/**
20
 * The main program of the CLI (command-line-interface).
21
 */
22
public final class Ideasy {
23

24
  private static final Logger LOG = LoggerFactory.getLogger(Ideasy.class);
4✔
25

26
  private AbstractIdeContext context;
27

28
  /**
29
   * The default constructor.
30
   */
31
  public Ideasy() {
32
    super();
×
33
  }
×
34

35
  /**
36
   * The constructor.
37
   *
38
   * @param context the predefined {@link IdeContext} for testing.
39
   */
40
  Ideasy(AbstractIdeContext context) {
41

42
    super();
2✔
43
    this.context = context;
3✔
44
  }
1✔
45

46
  /**
47
   * Non-static variant of {@link #main(String...) main method} without invoking {@link System#exit(int)} so it can be tested.
48
   *
49
   * @param args the command-line arguments.
50
   * @return the exit code.
51
   */
52
  public int run(String... args) {
53

54
    int exitStatus;
55
    try {
56
      exitStatus = runOrThrow(args);
4✔
57
    } catch (CliException error) {
1✔
58
      exitStatus = error.getExitCode();
3✔
59
      String errorMessage = error.getMessage();
3✔
60
      if ((errorMessage != null) && !errorMessage.isBlank()) {
5!
61
        LOG.error(errorMessage);
3✔
62
      }
63
    } catch (Throwable error) {
×
64
      exitStatus = 255;
×
65
      String title = error.getMessage();
×
66
      if (title == null) {
×
67
        title = error.getClass().getName();
×
68
      } else {
69
        title = error.getClass().getSimpleName() + ": " + title;
×
70
      }
71
      String message = "An unexpected error occurred!\n" //
×
72
          + "We are sorry for the inconvenience.\n" //
73
          + "Please check the error below, resolve it and try again.\n" //
74
          + "If the error is not on your end (network connectivity, lack of permissions, etc.) please file a bug:\n" //
75
          + "https://github.com/devonfw/IDEasy/issues/new?template=bug_report.yml&title="
76
          + URLEncoder.encode(title, StandardCharsets.UTF_8);
×
77
      LOG.error(message, error);
×
78
    }
2✔
79
    return exitStatus;
2✔
80
  }
81

82
  /**
83
   * Like {@link #run(String...)} but does not catch {@link Throwable}s so you can handle them yourself.
84
   *
85
   * @param args the command-line arguments.
86
   * @return the exit code.
87
   */
88
  public int runOrThrow(String... args) {
89

90
    CliArguments arguments = new CliArguments(args);
5✔
91
    initContext(arguments);
3✔
92
    return this.context.run(arguments);
5✔
93
  }
94

95
  private void initContext(CliArguments arguments) {
96

97
    IdeStartContextImpl startContext = null;
2✔
98
    if (this.context != null) {
3!
99
      startContext = this.context.getStartContext();
4✔
100
    }
101
    ContextCommandlet contextCommandlet = new ContextCommandlet(startContext);
5✔
102
    while (arguments.hasNext()) {
3✔
103
      CliArgument current = arguments.next();
3✔
104
      String key = current.getKey();
3✔
105
      Property<?> property = contextCommandlet.getOption(key);
4✔
106
      if (property == null) {
2✔
107
        if (CompleteCommandlet.NAME.equals(current.get())) {
5!
108
          arguments.preserveEndOptionsToken();
×
109
        }
110
        break;
111
      }
112
      String value = current.getValue();
3✔
113
      if (value == null) {
2!
114
        if (property instanceof FlagProperty) {
3!
115
          ((FlagProperty) property).setValue(Boolean.TRUE);
5✔
116
        } else {
117
          System.err.println("Missing value for option " + key);
×
118
        }
119
      } else {
120
        property.setValueAsString(value, this.context);
×
121
      }
122
    }
1✔
123
    contextCommandlet.run();
2✔
124
    if (this.context == null) {
3!
125
      startContext = contextCommandlet.getStartContext();
×
126
      this.context = new IdeContextConsole(startContext);
×
127
    }
128
  }
1✔
129

130
  /**
131
   * The actual main method of the CLI program.
132
   *
133
   * @param args the command-line arguments.
134
   */
135
  public static void main(String... args) {
136

137
    JulLogLevel.init();
×
138
    int exitStatus = new Ideasy().run(args);
×
139
    System.exit(exitStatus);
×
140
  }
×
141

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