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

devonfw / IDEasy / 12181235589

05 Dec 2024 01:58PM UTC coverage: 66.902% (-0.02%) from 66.917%
12181235589

push

github

web-flow
#508: enabled autocompletion for commandlet options (#833)

2527 of 4130 branches covered (61.19%)

Branch coverage included in aggregate %.

6577 of 9478 relevant lines covered (69.39%)

3.06 hits per line

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

75.0
cli/src/main/java/com/devonfw/tools/ide/commandlet/CommandletManager.java
1
package com.devonfw.tools.ide.commandlet;
2

3
import java.util.Collection;
4
import java.util.Iterator;
5

6
import com.devonfw.tools.ide.cli.CliArguments;
7
import com.devonfw.tools.ide.completion.CompletionCandidateCollector;
8
import com.devonfw.tools.ide.property.KeywordProperty;
9
import com.devonfw.tools.ide.property.Property;
10
import com.devonfw.tools.ide.tool.LocalToolCommandlet;
11
import com.devonfw.tools.ide.tool.ToolCommandlet;
12

13
/**
14
 * Interface to {@link #getCommandlet(Class) get} a {@link Commandlet} instance that is properly initialized.
15
 */
16
public interface CommandletManager {
17

18
  /**
19
   * @param <C> type of the {@link Commandlet}.
20
   * @param commandletType the {@link Class} reflecting the requested {@link Commandlet}.
21
   * @return the requested {@link Commandlet}.
22
   */
23
  <C extends Commandlet> C getCommandlet(Class<C> commandletType);
24

25
  /**
26
   * @param name the {@link Commandlet#getName() name} of the requested {@link Commandlet}.
27
   * @return the requested {@link Commandlet} or {@code null} if not found.
28
   */
29
  Commandlet getCommandlet(String name);
30

31
  /**
32
   * @param keyword the first keyword argument.
33
   * @return a {@link Commandlet} having the first {@link Property} {@link Property#isRequired() required} and a {@link KeywordProperty} with the given
34
   *     {@link Property#getName() name} or {@code null} if no such {@link Commandlet} is registered.
35
   */
36
  Commandlet getCommandletByFirstKeyword(String keyword);
37

38
  /**
39
   * @return the {@link Collection} of all registered {@link Commandlet}s.
40
   */
41
  Collection<Commandlet> getCommandlets();
42

43
  /**
44
   * @param name the {@link Commandlet#getName() name} of the requested {@link Commandlet}.
45
   * @return the requested {@link Commandlet}.
46
   * @throws IllegalArgumentException if not found.
47
   */
48
  default Commandlet getRequiredCommandlet(String name) {
49

50
    Commandlet commandlet = getCommandlet(name);
4✔
51
    if (commandlet == null) {
2!
52
      throw new IllegalArgumentException("The commandlet " + name + " could not be found!");
×
53
    }
54
    return commandlet;
2✔
55
  }
56

57
  /**
58
   * @param name the {@link Commandlet#getName() name} of the requested {@link ToolCommandlet}.
59
   * @return the requested {@link ToolCommandlet} or {@code null} if not found.
60
   */
61
  default ToolCommandlet getToolCommandlet(String name) {
62

63
    Commandlet commandlet = getCommandlet(name);
4✔
64
    if (commandlet instanceof ToolCommandlet tc) {
6!
65
      return tc;
2✔
66
    }
67
    return null;
×
68
  }
69

70
  /**
71
   * @param name the {@link Commandlet#getName() name} of the requested {@link ToolCommandlet}.
72
   * @return the requested {@link ToolCommandlet}.
73
   * @throws IllegalArgumentException if no {@link ToolCommandlet} exists with the given {@code name}.
74
   */
75
  default ToolCommandlet getRequiredToolCommandlet(String name) {
76

77
    Commandlet commandlet = getRequiredCommandlet(name);
4✔
78
    if (commandlet instanceof ToolCommandlet tc) {
6✔
79
      return tc;
2✔
80
    }
81
    throw new IllegalArgumentException("The commandlet " + name + " is not a ToolCommandlet!");
6✔
82
  }
83

84
  /**
85
   * @param name the {@link Commandlet#getName() name} of the requested {@link LocalToolCommandlet}.
86
   * @return the requested {@link LocalToolCommandlet}.
87
   * @throws IllegalArgumentException if no {@link LocalToolCommandlet} exists with the given {@code name}.
88
   */
89
  default LocalToolCommandlet getRequiredLocalToolCommandlet(String name) {
90

91
    Commandlet commandlet = getRequiredCommandlet(name);
4✔
92
    if (commandlet instanceof LocalToolCommandlet ltc) {
6!
93
      return ltc;
2✔
94
    }
95
    throw new IllegalArgumentException("The commandlet " + name + " is not a LocalToolCommandlet!");
×
96
  }
97

98
  /**
99
   * @param arguments the {@link CliArguments}.
100
   * @param collector the optional {@link CompletionCandidateCollector}. Will be {@code null} if no argument {@link CliArguments#isCompletion() completion}
101
   *     shall be performed.
102
   * @return an {@link Iterator} of the matching {@link Commandlet}(s). Typically empty or containing a single {@link Commandlet}. Only in edge-cases multiple
103
   *     {@link Commandlet}s could be found (e.g. if two {@link Commandlet}s exist with the same keyword but with different mandatory properties such as in our
104
   *     legacy devonfw-ide "ide get version ..." and "ide get edition ..." - however, we redesigned our CLI to "ide get-version ..." and "ide get-edition ..."
105
   *     to simplify this).
106
   */
107
  Iterator<Commandlet> findCommandlet(CliArguments arguments, CompletionCandidateCollector collector);
108

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