summaryrefslogtreecommitdiff
path: root/src/parameters_parser.hh
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2023-02-12 20:12:52 +0100
committerJohannes Altmanninger <aclopte@gmail.com>2023-02-17 20:50:58 +0100
commit64d4d29d43c78a403cff81d52ad0dabe06518f51 (patch)
treee2fd2c840166e4f319df69a588b899cf86182cc7 /src/parameters_parser.hh
parentafaa47e93fb937fbedb60bcdbc768bb937108f86 (diff)
Use parameter parser to skip switch args in completion
The command line "hook -group xyz " should get scope completions but it actually gets hook completions because "xyz" is wrongly interpreted as positional argument. Fix this by using the parameters parser to compute positional arguments. Fixes #4840
Diffstat (limited to 'src/parameters_parser.hh')
-rw-r--r--src/parameters_parser.hh11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/parameters_parser.hh b/src/parameters_parser.hh
index 69fa88eb..680c6f93 100644
--- a/src/parameters_parser.hh
+++ b/src/parameters_parser.hh
@@ -74,7 +74,13 @@ struct ParametersParser
// the options defines named options, if they map to true, then
// they are understood as string options, else they are understood as
// boolean option.
- ParametersParser(ParameterList params, const ParameterDesc& desc);
+ ParametersParser(ParameterList params, const ParameterDesc& desc, bool ignore_errors = false);
+
+ enum class State {
+ Switch,
+ SwitchArgument,
+ Positional,
+ };
// Return a valid optional if the switch was given, with
// a non empty StringView value if the switch took an argument.
@@ -132,10 +138,13 @@ struct ParametersParser
iterator begin() const { return iterator(*this, 0); }
iterator end() const { return iterator(*this, m_positional_indices.size()); }
+ State state() const { return *m_state; }
+
private:
ParameterList m_params;
Vector<size_t, MemoryDomain::Commands> m_positional_indices;
HashMap<String, StringView> m_switches;
+ Optional<State> m_state;
};
}