Search in sources :

Example 1 with Option

use of com.jetbrains.commandInterface.command.Option in project intellij-community by JetBrains.

the class CommandLineOptionReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    final LookupWithIndentsBuilder builder = new LookupWithIndentsBuilder();
    final ValidationResult validationResult = getValidationResult();
    if (validationResult == null) {
        return EMPTY_ARRAY;
    }
    for (final Option option : validationResult.getUnusedOptions()) {
        // Suggest long options for -- and short for -
        final List<String> names = getElement().isLong() ? option.getLongNames() : option.getShortNames();
        for (final String optionName : names) {
            builder.addElement(LookupElementBuilder.create(optionName), option.getHelp().getHelpString());
        }
    }
    return builder.getResult();
}
Also used : CommandLineOption(com.jetbrains.commandInterface.commandLine.psi.CommandLineOption) Option(com.jetbrains.commandInterface.command.Option) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with Option

use of com.jetbrains.commandInterface.command.Option in project intellij-community by JetBrains.

the class ValidationResultImpl method visitOption.

@Override
public void visitOption(@NotNull final CommandLineOption o) {
    super.visitOption(o);
    if (myUnusedOptions.containsKey(o.getOptionName())) {
        // Remove from list of available options
        final Option option = myUnusedOptions.remove(o.getOptionName());
        for (final String optionName : option.getAllNames()) {
            myUnusedOptions.remove(optionName);
        }
        final Pair<Integer, Argument> argumentAndQuantity = option.getArgumentAndQuantity();
        if (argumentAndQuantity != null) {
            myCurrentOptionAndArgsLeft = Pair.create(option, argumentAndQuantity.first);
        } else {
            myCurrentOptionAndArgsLeft = new Pair<>(option, 0);
        }
    } else {
        //No such option available
        myBadValues.add(o);
    }
}
Also used : Argument(com.jetbrains.commandInterface.command.Argument) Option(com.jetbrains.commandInterface.command.Option)

Example 3 with Option

use of com.jetbrains.commandInterface.command.Option in project intellij-community by JetBrains.

the class CommandLinePsiImplUtils method findBestHelp.

/**
   * Tries to find appropriate help for argument. It can be argument help for positional argument or option help
   * for option argument.
   *
   * @param argument argument to search help for
   * @return help for argument or null if not found
   */
@Nullable
static Help findBestHelp(@NotNull final CommandLineArgument argument) {
    final Option option = argument.findOptionForOptionArgument();
    if (option != null) {
        return option.getHelp();
    }
    final Argument realArgument = argument.findRealArgument();
    return (realArgument != null ? realArgument.getHelp() : null);
}
Also used : CommandLineArgument(com.jetbrains.commandInterface.commandLine.psi.CommandLineArgument) Argument(com.jetbrains.commandInterface.command.Argument) CommandLineOption(com.jetbrains.commandInterface.commandLine.psi.CommandLineOption) Option(com.jetbrains.commandInterface.command.Option) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with Option

use of com.jetbrains.commandInterface.command.Option in project intellij-community by JetBrains.

the class CommandLineArgumentReference method getVariants.

@NotNull
@Override
public Object[] getVariants() {
    final LookupWithIndentsBuilder builder = new LookupWithIndentsBuilder();
    final Argument argument = getElement().findRealArgument();
    final Option argumentOption = getElement().findOptionForOptionArgument();
    final Collection<String> argumentValues = (argument != null ? argument.getAvailableValues() : null);
    // priority is used to display args before options
    if (argumentValues != null) {
        for (final String value : argumentValues) {
            final Help help = getElement().findBestHelp();
            final String helpText = (help != null ? help.getHelpString() : null);
            builder.addElement(LookupElementBuilder.create(value).withBoldness(true), helpText, 1);
        }
    }
    final ValidationResult validationResult = getValidationResult();
    if (validationResult == null) {
        return EMPTY_ARRAY;
    }
    if (argumentOption == null) {
        // If not option argument
        for (final Option option : validationResult.getUnusedOptions()) {
            for (final String value : option.getAllNames()) {
                builder.addElement(LookupElementBuilder.create(value), option.getHelp().getHelpString(), 0);
            }
        }
    }
    return builder.getResult();
}
Also used : Help(com.jetbrains.commandInterface.command.Help) CommandLineArgument(com.jetbrains.commandInterface.commandLine.psi.CommandLineArgument) Argument(com.jetbrains.commandInterface.command.Argument) Option(com.jetbrains.commandInterface.command.Option) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Option (com.jetbrains.commandInterface.command.Option)4 Argument (com.jetbrains.commandInterface.command.Argument)3 CommandLineArgument (com.jetbrains.commandInterface.commandLine.psi.CommandLineArgument)2 CommandLineOption (com.jetbrains.commandInterface.commandLine.psi.CommandLineOption)2 NotNull (org.jetbrains.annotations.NotNull)2 Help (com.jetbrains.commandInterface.command.Help)1 Nullable (org.jetbrains.annotations.Nullable)1