Java Code Examples for picocli.CommandLine.Model.PositionalParamSpec#hidden()

The following examples show how to use picocli.CommandLine.Model.PositionalParamSpec#hidden() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AutoComplete.java    From picocli with Apache License 2.0 5 votes vote down vote up
private static String generatePositionalParamsCases(List<PositionalParamSpec> posParams, String indent, String currWord) {
    StringBuilder buff = new StringBuilder(1024);
    for (PositionalParamSpec param : posParams) {
        if (param.hidden()) { continue; } // #887 skip hidden params
        Class<?> type = param.type();
        if (param.typeInfo().isMultiValue()) {
            type = param.typeInfo().getAuxiliaryTypes()[0];
        }
        String paramName = bashify(param.paramLabel());
        String ifOrElif = buff.length() > 0 ? "elif" : "if";
        int min = param.index().min();
        int max = param.index().max();
        if (param.completionCandidates() != null) {
            buff.append(format("%s    %s (( currIndex >= %d && currIndex <= %d )); then\n", indent, ifOrElif, min, max));
            buff.append(format("%s      positionals=$( compgen -W \"$%s_pos_param_args\" -- \"%s\" )\n", indent, paramName, currWord));
        } else if (type.equals(File.class) || "java.nio.file.Path".equals(type.getName())) {
            buff.append(format("%s    %s (( currIndex >= %d && currIndex <= %d )); then\n", indent, ifOrElif, min, max));
            buff.append(format("%s      compopt -o filenames\n", indent));
            buff.append(format("%s      positionals=$( compgen -f -- \"%s\" ) # files\n", indent, currWord));
        } else if (type.equals(InetAddress.class)) {
            buff.append(format("%s    %s (( currIndex >= %d && currIndex <= %d )); then\n", indent, ifOrElif, min, max));
            buff.append(format("%s      compopt -o filenames\n", indent));
            buff.append(format("%s      positionals=$( compgen -A hostname -- \"%s\" )\n", indent, currWord));
        }
    }
    if (buff.length() > 0) {
        buff.append(format("%s    fi\n", indent));
    }
    return buff.toString();
}
 
Example 2
Source File: AutoComplete.java    From picocli with Apache License 2.0 5 votes vote down vote up
private static void addCandidatesForArgsFollowing(CommandSpec commandSpec, List<CharSequence> candidates) {
    if (commandSpec == null) { return; }
    for (Map.Entry<String, CommandLine> entry : commandSpec.subcommands().entrySet()) {
        if (entry.getValue().getCommandSpec().usageMessage().hidden()) { continue; } // #887 skip hidden subcommands
        candidates.add(entry.getKey());
        candidates.addAll(Arrays.asList(entry.getValue().getCommandSpec().aliases()));
    }
    candidates.addAll(commandSpec.optionsMap().keySet());
    for (PositionalParamSpec positional : commandSpec.positionalParameters()) {
        if (positional.hidden()) { continue; } // #887 skip hidden subcommands
        addCandidatesForArgsFollowing(positional, candidates);
    }
}
 
Example 3
Source File: AutoComplete.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
private static String generatePositionalParamsCases(List<PositionalParamSpec> posParams, String indent, String currWord) {
    StringBuilder buff = new StringBuilder(1024);
    for (PositionalParamSpec param : posParams) {
        if (param.hidden()) { continue; } // #887 skip hidden params
        Class<?> type = param.type();
        if (param.typeInfo().isMultiValue()) {
            type = param.typeInfo().getAuxiliaryTypes()[0];
        }
        String paramName = bashify(param.paramLabel());
        String ifOrElif = buff.length() > 0 ? "elif" : "if";
        int min = param.index().min();
        int max = param.index().max();
        if (param.completionCandidates() != null) {
            buff.append(format("%s    %s (( currIndex >= %d && currIndex <= %d )); then\n", indent, ifOrElif, min, max));
            buff.append(format("%s      positionals=$( compgen -W \"$%s_pos_param_args\" -- \"%s\" )\n", indent, paramName, currWord));
        } else if (type.equals(File.class) || "java.nio.file.Path".equals(type.getName())) {
            buff.append(format("%s    %s (( currIndex >= %d && currIndex <= %d )); then\n", indent, ifOrElif, min, max));
            buff.append(format("%s      compopt -o filenames\n", indent));
            buff.append(format("%s      positionals=$( compgen -f -- \"%s\" ) # files\n", indent, currWord));
        } else if (type.equals(InetAddress.class)) {
            buff.append(format("%s    %s (( currIndex >= %d && currIndex <= %d )); then\n", indent, ifOrElif, min, max));
            buff.append(format("%s      compopt -o filenames\n", indent));
            buff.append(format("%s      positionals=$( compgen -A hostname -- \"%s\" )\n", indent, currWord));
        }
    }
    if (buff.length() > 0) {
        buff.append(format("%s    fi\n", indent));
    }
    return buff.toString();
}
 
Example 4
Source File: AutoComplete.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
private static void addCandidatesForArgsFollowing(CommandSpec commandSpec, List<CharSequence> candidates) {
    if (commandSpec == null) { return; }
    for (Map.Entry<String, CommandLine> entry : commandSpec.subcommands().entrySet()) {
        if (entry.getValue().getCommandSpec().usageMessage().hidden()) { continue; } // #887 skip hidden subcommands
        candidates.add(entry.getKey());
        candidates.addAll(Arrays.asList(entry.getValue().getCommandSpec().aliases()));
    }
    candidates.addAll(commandSpec.optionsMap().keySet());
    for (PositionalParamSpec positional : commandSpec.positionalParameters()) {
        if (positional.hidden()) { continue; } // #887 skip hidden subcommands
        addCandidatesForArgsFollowing(positional, candidates);
    }
}
 
Example 5
Source File: AutoComplete.java    From picocli with Apache License 2.0 4 votes vote down vote up
private static void addCandidatesForArgsFollowing(PositionalParamSpec positionalSpec, List<CharSequence> candidates) {
    if (positionalSpec != null && !positionalSpec.hidden()) {
        addCompletionCandidates(positionalSpec.completionCandidates(), candidates);
    }
}
 
Example 6
Source File: AutoComplete.java    From Flashtool with GNU General Public License v3.0 4 votes vote down vote up
private static void addCandidatesForArgsFollowing(PositionalParamSpec positionalSpec, List<CharSequence> candidates) {
    if (positionalSpec != null && !positionalSpec.hidden()) {
        addCompletionCandidates(positionalSpec.completionCandidates(), candidates);
    }
}