aboutsummaryrefslogtreecommitdiff
path: root/src/libutil/args.hh
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2020-05-10 21:35:07 +0200
committerEelco Dolstra <edolstra@gmail.com>2020-05-10 21:35:07 +0200
commite0c19ee620c53b52ca7cf69c19d414d782338be1 (patch)
treea28571713bc2558e09798d2f4bdc2d0220802649 /src/libutil/args.hh
parent91ddee6bf045b1c6144d14233abdb96127186ec3 (diff)
Add completion for paths
Diffstat (limited to 'src/libutil/args.hh')
-rw-r--r--src/libutil/args.hh12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/libutil/args.hh b/src/libutil/args.hh
index ae2875e72..f93459c96 100644
--- a/src/libutil/args.hh
+++ b/src/libutil/args.hh
@@ -83,6 +83,7 @@ protected:
std::string category;
Strings labels;
Handler handler;
+ std::function<void(size_t, std::string_view)> completer;
static Flag mkHashTypeFlag(std::string && longName, HashType * ht);
};
@@ -98,8 +99,8 @@ protected:
struct ExpectedArg
{
std::string label;
- size_t arity; // 0 = any
- bool optional;
+ size_t arity = 0; // 0 = any
+ bool optional = false;
std::function<void(std::vector<std::string>)> handler;
};
@@ -182,6 +183,8 @@ public:
}});
}
+ void expectPathArg(const std::string & label, string * dest, bool optional = false);
+
/* Expect 0 or more arguments. */
void expectArgs(const std::string & label, std::vector<std::string> * dest)
{
@@ -190,6 +193,8 @@ public:
}});
}
+ void expectPathArgs(const std::string & label, std::vector<std::string> * dest);
+
friend class MultiCommand;
};
@@ -257,7 +262,10 @@ typedef std::vector<std::pair<std::string, std::string>> Table2;
void printTable(std::ostream & out, const Table2 & table);
extern std::shared_ptr<std::set<std::string>> completions;
+extern bool pathCompletions;
std::optional<std::string> needsCompletion(std::string_view s);
+void completePath(size_t, std::string_view s);
+
}