Allow initialization of values for shell completion in callback

Use case is implementing completion for syncthingctl also for
device and folder IDs.
experiment/srcref_basic_cfg
Martchus 5 years ago
parent b7b218c831
commit 46bfbdd829
  1. 3
      application/argumentparser.cpp
  2. 3
      application/argumentparser.h

@ -1054,6 +1054,9 @@ void ArgumentParser::printBashCompletion(int argc, const char *const *argv, unsi
cout << "COMPREPLY=(";
// -> completions for parameter values
for (const Argument *arg : relevantPreDefinedValues) {
if (arg->valueCompletionBehaviour() & ValueCompletionBehavior::InvokeCallback && arg->m_callbackFunction) {
arg->m_callbackFunction(arg->isPresent() ? arg->m_occurrences.front() : ArgumentOccurrence(Argument::varValueCount));
}
if (arg->preDefinedCompletionValues()) {
bool appendEquationSign = arg->valueCompletionBehaviour() & ValueCompletionBehavior::AppendEquationSign;
if (argc && currentWordIndex <= lastSpecifiedArgIndex && opening) {

@ -74,7 +74,8 @@ enum class ValueCompletionBehavior : unsigned char {
Files = 4, /**< files */
Directories = 8, /**< directories */
FileSystemIfNoPreDefinedValues = 16, /**< files and directories but only if no values have been assigned (default behavior) */
AppendEquationSign = 32 /**< an equation sign is appended to values which not contain an equation sign already */
AppendEquationSign = 32, /**< an equation sign is appended to values which not contain an equation sign already */
InvokeCallback = 64, /**< whether to invoke the callback before reading pre-defined values */
};
/// \cond

Loading…
Cancel
Save