org.apache.felix.gogo.commands.Option类的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(129)

本文整理了Java中org.apache.felix.gogo.commands.Option类的一些代码示例,展示了Option类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Option类的具体详情如下:
包路径:org.apache.felix.gogo.commands.Option
类名称:Option

Option介绍

暂无

代码示例

代码示例来源:origin: org.apache.karaf.shell/org.apache.karaf.shell.obr

@Command(scope = "obr", name = "deploy", description = "Deploys a list of bundles using OBR service.")
public class DeployCommand extends ObrCommandSupport {

  @Argument(index = 0, name = "bundles", description = "List of bundle names to deploy (separated by whitespaces). The bundles are identified using the following syntax: symbolic_name,version where version is optional.", required = true, multiValued = true)
  protected List<String> bundles;

  @Option(name = "-s", aliases = { "--start" }, description = "Start all deployed bundles", required = false, multiValued = false)
  protected boolean start = false;

  @Option(name = "-d", aliases = { "--deployOptional" }, description = "Deploy optional bundles", required = false, multiValued = false)
  protected boolean deployOptional = false;

  protected void doExecute(RepositoryAdmin admin) throws Exception {
    doDeploy(admin, bundles, start, deployOptional);
  }

}

代码示例来源:origin: apache/karaf

@Override
  public String[] aliases() {
    return oldOption.aliases();
  }
};

代码示例来源:origin: apache/karaf

@Override
public String description() {
  return oldOption.description();
}

代码示例来源:origin: com.redhat.rhevm.api/rhevm-api-cli-templates

/**
 * Displays the Templates
 */
@Command(scope = "templates", name = "list", description = "Lists Templates.")
public class TemplatesListCommand extends AbstractListCommand<Template> {

  @Option(name = "-b", aliases = {"--bound"}, description="Upper bound on number of Templates to display", required = false, multiValued = false)
  protected int limit = Integer.MAX_VALUE;

  @Option(name = "-s", aliases = {"--search"}, description="Query constraint on Templates", required = false, multiValued = false)
  protected String constraint;

  protected Object doExecute() throws Exception {
    doList(client.getCollection("templates", Templates.class, constraint).getTemplates(), limit);
    return null;
  }
}

代码示例来源:origin: org.apache.karaf.shell/org.apache.karaf.shell.osgi

public abstract class BundlesCommand extends OsgiCommandSupport {

  @Argument(index = 0, name = "ids", description = "The list of bundle (identified by IDs or name or name/version) separated by whitespaces", required = true, multiValued = true)
  List<String> ids;

  @Option(name = "--force", aliases = {}, description = "Forces the command to execute", required = false, multiValued = false)
  boolean force;

  protected Object doExecute() throws Exception {
    BundleSelector selector = new BundleSelector(getBundleContext(), session);      
    List<Bundle> bundles = selector.selectBundles(ids, force);
    doExecute(bundles);
    return null;
  }
   
  protected abstract void doExecute(List<Bundle> bundles) throws Exception;
}

代码示例来源:origin: io.fabric8/process-fabric

public abstract class ContainerInstallSupport extends ContainerProcessCommandSupport {

  @Option(name="-c", aliases={"--controllerUrl"}, required = false, description = "The optional JSON document URL containing the controller configuration")
  protected String controllerJson;
  @Option(name="-k", aliases={"--kind"}, required = false, description = "The kind of controller to create")
  protected String controllerKind;

  protected URL getControllerURL() throws MalformedURLException {
    URL controllerUrl = null;
    if (controllerJson != null) {
      controllerUrl = new URL(controllerJson);
    } else if (controllerKind != null) {
      String name = controllerKind + ".json";
      controllerUrl = new URL("profile:" + name);
      if (controllerUrl == null) {
        throw new IllegalStateException("Cannot find controller kind: " + name + " on the classpath");
      }
    }
    return controllerUrl;
  }

}

代码示例来源:origin: org.apache.felix.gogo/org.apache.felix.gogo.commands

Object param = it.next();
if (HELP.name().equals(param) || Arrays.asList(HELP.aliases()).contains(param)) {
  printUsage(action.getClass().getAnnotation(Command.class), options.keySet(), arguments.keySet(), System.out);
  return false;
    if (name.equals(opt.name()) || Arrays.binarySearch(opt.aliases(), name) >= 0) {
      option = opt;
      break;
    throw new IllegalArgumentException("Missing value for option " + param);
  if (option.multiValued()) {
    List<Object> l = (List<Object>) optionValues.get(option);
    if (l == null) {
  if (!argument.multiValued()) {
    argIndex++;
  if (argument.multiValued()) {
    List<Object> l = (List<Object>) argumentValues.get(argument);
    if (l == null) {
if (option.required() && optionValues.get(option) == null) {
  throw new IllegalArgumentException("Option " + option.name() + " is required");

代码示例来源:origin: org.apache.felix.gogo/org.apache.felix.gogo.commands

if (command != null && command.description() != null && command.description().length() > 0)
  out.println(command.description());
  out.println();
    out.print(argument.name());
    out.print("  ");
    out.print(argument.description());
    out.println();
    out.print(option.name());
    out.print("  ");
    if (option.aliases().length > 0)
      out.print(Arrays.toString(option.aliases()));
      out.print(")  ");
    out.print(option.description());
    out.println();

代码示例来源:origin: apache/karaf

Set<Option> options = new HashSet<>(optionsMap.keySet());
options.add(HELP);
boolean globalScope = NameScoping.isGlobalScope(session, command.scope());
if (command != null && (command.description() != null || command.name() != null)) {
  out.println(INTENSITY_BOLD + "DESCRIPTION" + INTENSITY_NORMAL);
  out.print("        ");
  out.println(INTENSITY_BOLD + "OPTIONS" + INTENSITY_NORMAL);
  for (Option option : options) {
    String opt = option.name();
    for (String alias : option.aliases()) {
      opt += ", " + alias;
    printFormatted("                ", option.description(), width, out);
    if (option.valueToShowInHelp() != null && option.valueToShowInHelp().length() != 0) {
      try {
        if (Option.DEFAULT_STRING.equals(option.valueToShowInHelp())) {
          optionsMap.get(option).setAccessible(true);
          Object o = optionsMap.get(option).get(action);
          printObjectDefaultsTo(out, o);
        } else {
          printDefaultsTo(out, option.valueToShowInHelp());

代码示例来源:origin: apache/karaf

if (option != null) {
  fields.put(option, field);
  options.put(option.name(), option);
  String[] aliases = option.aliases();
  if (aliases != null) {
    for (String alias : aliases) {
  Integer key = argument.index();
  if (arguments.containsKey(key)) {
    LOGGER.warn("Duplicate @Argument annotations on class " + type.getName() + " for index: " + key + " see: " + field);

代码示例来源:origin: apache/karaf

if (option != null) {
  Completer optionValueCompleter = null;
  String name = option.name();
  if (optionalCompleters != null && name != null) {
    optionValueCompleter = optionalCompleters.get(name);
    if (optionValueCompleter == null) {
      String[] aliases = option.aliases();
      if (aliases.length > 0) {
        for (int i = 0; i < aliases.length && optionValueCompleter == null; i++) {
          optionValueCompleter = optionalCompleters.get(option.aliases()[i]);

代码示例来源:origin: apache/karaf

@Override
public String name() {
  return oldOption.name();
}

代码示例来源:origin: com.redhat.rhevm.api/rhevm-api-cli-vms

/**
 * Displays the VMs
 */
@Command(scope = "vms", name = "list", description = "Lists Virtual Machines.")
public class VmsListCommand extends AbstractListCommand<VM> {

  @Option(name = "-b", aliases = {"--bound"}, description="Upper bound on number of VMs to display", required = false, multiValued = false)
  protected int limit = Integer.MAX_VALUE;

  @Option(name = "-s", aliases = {"--search"}, description="Query constraint on VMs", required = false, multiValued = false)
  protected String constraint;

  protected Object doExecute() throws Exception {
    doList(client.getCollection("vms", VMs.class, constraint).getVMs(), limit);
    return null;
  }
}

代码示例来源:origin: org.fusesource.fabric/fabric-commands

public abstract class ContainerLifecycleCommand extends FabricCommand {

  @Option(name = "--user", description = "The username to use.")
  String user;

  @Option(name = "--password", description = "The password to use.")
  String password;

  @Argument(index = 0, name = "container", description = "The container name", required = true, multiValued = false)
  String container = null;

  void applyUpdatedCredentials(Container container) {
    if (user != null || password != null) {
      CreateContainerMetadata metadata = container.getMetadata();
      if (metadata != null) {
        metadata.updateCredentials(user, password);
        container.setMetadata(metadata);
      }
    }
  }
}

代码示例来源:origin: org.fusesource.fabric/process-manager

/**
 */
public abstract class InstallSupport extends ProcessCommandSupport {
  @Option(name="-c", aliases={"--controllerUrl"}, required = false, description = "The optional JSON document URL containing the controller configuration")
  protected String controllerJson;
  @Option(name="-k", aliases={"--kind"}, required = false, description = "The kind of controller to create")
  protected String controllerKind;

  protected URL getControllerURL() throws MalformedURLException {
    URL controllerUrl = null;
    if (controllerJson != null) {
      controllerUrl = new URL(controllerJson);
    } else if (controllerKind != null) {
      String name = controllerKind + ".json";
      controllerUrl = getBundleContext().getBundle().getResource(name);
      if (controllerUrl == null) {
        throw new IllegalStateException("Cannot find controller kind: " + name + " on the classpath");
      }
    }
    return controllerUrl;
  }
}

代码示例来源:origin: apache/karaf

if (HELP.name().equals(param) || Arrays.asList(HELP.aliases()).contains(param)) {
  printUsage(session, action, options, arguments, System.out);
  return false;
    if (name.equals(opt.name()) || Arrays.asList(opt.aliases()).contains(name)) {
      option = opt;
      break;
  if (option.multiValued()) {
    List<Object> l = (List<Object>) optionValues.get(option);
    if (l == null) {
if (option.required() && optionValues.get(option) == null) {
  Command command = action.getClass().getAnnotation(Command.class);
  if (command != null) {
                  + INTENSITY_BOLD + option.name() + INTENSITY_NORMAL
                  + " is required"
                  + COLOR_DEFAULT,
        "Option " + option.name() + " is required"
    );
  } else {
    throw new CommandException("Option " + option.name() + " is required");
                  + INTENSITY_BOLD + entry.getKey().name() + INTENSITY_NORMAL
                  + " with value '" + entry.getValue() + "' to type "
                  + new GenericType(field.getGenericType()).toString()
                  + COLOR_DEFAULT,
        "Unable to convert option " + entry.getKey().name() + " with value '"

代码示例来源:origin: org.apache.felix.karaf.shell/org.apache.felix.karaf.shell.console

options = new HashSet<Option>(options);
options.add(HELP);
if (command != null && (command.description() != null || command.name() != null))
  if (command.name() != null) {
    out.println(Ansi.ansi().a(command.scope()).a(":").a(Ansi.Attribute.INTENSITY_BOLD).a(command.name()).a(Ansi.Attribute.RESET));
    out.println();
  for (Argument argument : arguments)
    if (!argument.required())
      syntax.append(String.format("[%s] ", argument.name()));
      syntax.append(String.format("%s ", argument.name()));
  for (Option option : options)
    String opt = option.name();
    for (String alias : option.aliases())
    out.println(String.format("\t%-15s%s", "", option.description()));

代码示例来源:origin: apache/karaf

if (option != null) {
  fields.put(option, field);
  options.put(option.name(), option);
  String[] aliases = option.aliases();
  if (aliases != null) {
    for (String alias : aliases) {
  Integer key = argument.index();
  if (arguments.containsKey(key)) {
    LOGGER.warn("Duplicate @Argument annotations on class " + type.getName() + " for index: " + key + " see: " + field);

代码示例来源:origin: apache/karaf

if (option != null) {
  Completer optionValueCompleter = null;
  String name = option.name();
  if (optionalCompleters != null && name != null) {
    optionValueCompleter = optionalCompleters.get(name);
    if (optionValueCompleter == null) {
      String[] aliases = option.aliases();
      if (aliases.length > 0) {
        for (int i = 0; i < aliases.length && optionValueCompleter == null; i++) {
          optionValueCompleter = optionalCompleters.get(option.aliases()[i]);

代码示例来源:origin: org.apache.felix.karaf.shell/org.apache.felix.karaf.shell.admin

@Command(scope = "admin", name = "connect", description = "Connect to an existing instance.")
public class ConnectCommand extends AdminCommandSupport {

  @Argument(index=0, name="INSTANCE", required=true, description="The instance name")
  private String instance = null;

  @Option(name="-u", aliases={"--username"}, description="Remote user name")
  private String username = "karaf";

  @Option(name="-p", aliases={"--password"}, description="Remote user password")
  private String password = "karaf";

  protected Object doExecute() throws Exception {
    int port = getExistingInstance(instance).getPort();
    session.execute("ssh -l " + username + " -P " + password + " -p " + port + " localhost");
    return null;
  }
}

相关文章