diff --git a/airline-help/airline-help-bash/src/main/java/com/github/rvesse/airline/help/cli/bash/BashCompletionGenerator.java b/airline-help/airline-help-bash/src/main/java/com/github/rvesse/airline/help/cli/bash/BashCompletionGenerator.java index dcbfd36c5..6728438e3 100644 --- a/airline-help/airline-help-bash/src/main/java/com/github/rvesse/airline/help/cli/bash/BashCompletionGenerator.java +++ b/airline-help/airline-help-bash/src/main/java/com/github/rvesse/airline/help/cli/bash/BashCompletionGenerator.java @@ -393,15 +393,24 @@ private void generateCommandCompletionFunction(Writer writer, GlobalMetadata writeWordListVariable(writer, 2, "FLAG_OPTS", flagOpts.iterator()); writeWordListVariable(writer, 2, "ARG_OPTS", argOpts.iterator()); writer.append(NEWLINE); + + // Check whether we've seen the arguments separator + writer.append(" $( containsElement \"").append(global.getParserConfiguration().getArgumentsSeparator()).append("\" ${COMP_WORDS[@]} )"); + writer.append(" SAW_ARGS_SEPARATOR=$?"); + writer.append(" if [[ ${SAW_ARGS_SEPARATOR} -eq 0 ]]; then"); + + // TODO Do completion specifically for arguments + + writer.append(" fi"); - // Check whether we are completing a value for an argument flag + // Check whether we are completing a value for an option if (argOpts.size() > 0) { writer.append(" $( containsElement ${PREV_WORD} ${ARG_OPTS[@]} )").append(NEWLINE); - writer.append(" SAW_ARG=$?").append(NEWLINE); + writer.append(" SAW_OPTION=$?").append(NEWLINE); // If we previously saw an argument then we are completing that // argument - writer.append(" if [[ ${SAW_ARG} -eq 0 ]]; then").append(NEWLINE); + writer.append(" if [[ ${SAW_OPTION} -eq 0 ]]; then").append(NEWLINE); writer.append(" ARG_VALUES=").append(NEWLINE); writer.append(" ARG_GENERATED_VALUES=").append(NEWLINE); writer.append(" case ${PREV_WORD} in").append(NEWLINE); @@ -439,7 +448,7 @@ private void generateCommandCompletionFunction(Writer writer, GlobalMetadata writer.append(" fi").append(DOUBLE_NEWLINE); } - // If we previously saw a flag we could see another option or an + // If we previously saw a flag option we could see another option or an // argument if supported BashCompletion completion = null; if (command.getArguments() != null) { diff --git a/airline-help/airline-help-man/src/main/java/com/github/rvesse/airline/help/man/ManCommandUsageGenerator.java b/airline-help/airline-help-man/src/main/java/com/github/rvesse/airline/help/man/ManCommandUsageGenerator.java index 2324c23dd..66dc343b7 100644 --- a/airline-help/airline-help-man/src/main/java/com/github/rvesse/airline/help/man/ManCommandUsageGenerator.java +++ b/airline-help/airline-help-man/src/main/java/com/github/rvesse/airline/help/man/ManCommandUsageGenerator.java @@ -91,9 +91,9 @@ public void usage(String programName, String[] groupNames, String commandNam helper.outputHelpSection(printer, section); } - List options = outputSynopsis(printer, programName, groupNames, commandName, command); + List options = outputSynopsis(printer, programName, groupNames, commandName, command, parserConfig); - if (options.size() > 0 || command.getArguments() != null) { + if (options.size() > 0 || command.hasAnyArguments()) { outputOptions(printer, command, options, parserConfig); } @@ -127,7 +127,7 @@ protected void outputOptions(TroffPrinter printer, CommandMetadata command, ParserMetadata parserConfig) throws IOException { // Options // Can end the list if there are no arguments - int optionsOutput = helper.outputOptions(printer, options, command.getArguments() == null); + int optionsOutput = helper.outputOptions(printer, options, !command.hasAnyArguments()); // Arguments // Must start the list if there are no visible options @@ -152,8 +152,8 @@ protected void outputOptions(TroffPrinter printer, CommandMetadata command, * @throws IOException * Thrown if there is a problem generating usage output */ - protected List outputSynopsis(TroffPrinter printer, String programName, String[] groupNames, - String commandName, CommandMetadata command) throws IOException { + protected List outputSynopsis(TroffPrinter printer, String programName, String[] groupNames, + String commandName, CommandMetadata command, ParserMetadata parserConfig) throws IOException { printer.nextSection("SYNOPSIS"); List options = new ArrayList<>(); @@ -200,9 +200,9 @@ protected List outputSynopsis(TroffPrinter printer, String progr options.addAll(aOptions); // Command arguments (optional) - if (command.getArguments() != null) { + if (command.hasAnyArguments()) { printer.print(" [ "); - printer.printBold("--"); + printer.printBold(parserConfig.getArgumentsSeparator()); printer.print(" ] "); this.helper.outputArgumentsSynopsis(printer, command.getPositionalArguments(), command.getArguments()); } diff --git a/airline-help/airline-help-man/src/main/java/com/github/rvesse/airline/help/man/ManUsageHelper.java b/airline-help/airline-help-man/src/main/java/com/github/rvesse/airline/help/man/ManUsageHelper.java index ccb4c44b3..705c99cd6 100644 --- a/airline-help/airline-help-man/src/main/java/com/github/rvesse/airline/help/man/ManUsageHelper.java +++ b/airline-help/airline-help-man/src/main/java/com/github/rvesse/airline/help/man/ManUsageHelper.java @@ -91,10 +91,10 @@ public int outputOptions(TroffPrinter printer, List options, boo return output; } - public void outputArguments(TroffPrinter printer, List posArgs, ArgumentsMetadata arguments, boolean startList, - ParserMetadata parserConfig) throws IOException { + public void outputArguments(TroffPrinter printer, List posArgs, + ArgumentsMetadata arguments, boolean startList, ParserMetadata parserConfig) throws IOException { boolean needsArgsSeparator = (posArgs != null && posArgs.size() > 0) || arguments != null; - + if (needsArgsSeparator) { // Arguments separator option if (startList) { @@ -113,30 +113,30 @@ public void outputArguments(TroffPrinter printer, List 0) { for (PositionalArgumentMetadata posArg : posArgs) { // Argument name printer.nextTitledListItem(); printer.printItalic(posArg.getTitle()); - + // Description printer.startPlainList(); printer.println(posArg.getDescription()); - + // Restrictions List hints = sortArgumentsRestrictions(arguments.getRestrictions()); for (HelpHint hint : hints) { - // Safe to cast back to ArgumentsRestriction as must have come + // Safe to cast back to ArgumentsRestriction as must have + // come // from an ArgumentsRestriction to start with outputArgumentsRestriction(printer, arguments, (ArgumentsRestriction) hint, hint); } printer.endList(); } } - - if (arguments != null) { + if (arguments != null) { // Arguments name(s) printer.nextTitledListItem(); @@ -155,9 +155,12 @@ public void outputArguments(TroffPrinter printer, List void usage(String programName, String[] groupNames, String commandNam } // Synopsis - List options = outputSynopsis(out, programName, groupNames, commandName, command); + List options = outputSynopsis(out, programName, groupNames, commandName, command, parserConfig); // Options ArgumentsMetadata arguments = command.getArguments(); @@ -142,8 +142,8 @@ protected void outputOptionsAndArguments(UsagePrinter out, CommandMetadata c * @throws IOException * Thrown if there is a problem generating usage output */ - protected List outputSynopsis(UsagePrinter out, String programName, String[] groupNames, - String commandName, CommandMetadata command) throws IOException { + protected List outputSynopsis(UsagePrinter out, String programName, String[] groupNames, + String commandName, CommandMetadata command, ParserMetadata parserConfig) throws IOException { out.append("# SYNOPSIS").newline().newline(); List options = new ArrayList<>(); @@ -164,8 +164,8 @@ protected List outputSynopsis(UsagePrinter out, String programNa options.addAll(command.getCommandOptions()); // command arguments (optional) - if (command.getArguments() != null) { - out.append("[ `--` ]"); + if (command.hasAnyArguments()) { + out.append(String.format("[ `%s` ]", parserConfig.getArgumentsSeparator())); helper.outputArgumentsSynopsis(out, command.getArguments()); } out.newline();