mirror of
https://github.com/NixOS/nix
synced 2025-07-05 04:01:47 +02:00
Merge pull request #9212 from trofkm/args-refactoring
Clean up `args.hh`
This commit is contained in:
commit
3ca0dade5b
1 changed files with 13 additions and 13 deletions
|
@ -57,7 +57,7 @@ protected:
|
||||||
std::function<void(std::vector<std::string>)> fun;
|
std::function<void(std::vector<std::string>)> fun;
|
||||||
size_t arity;
|
size_t arity;
|
||||||
|
|
||||||
Handler() {}
|
Handler() = default;
|
||||||
|
|
||||||
Handler(std::function<void(std::vector<std::string>)> && fun)
|
Handler(std::function<void(std::vector<std::string>)> && fun)
|
||||||
: fun(std::move(fun))
|
: fun(std::move(fun))
|
||||||
|
@ -84,29 +84,29 @@ protected:
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Handler(std::vector<std::string> * dest)
|
Handler(std::vector<std::string> * dest)
|
||||||
: fun([=](std::vector<std::string> ss) { *dest = ss; })
|
: fun([dest](std::vector<std::string> ss) { *dest = ss; })
|
||||||
, arity(ArityAny)
|
, arity(ArityAny)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Handler(std::string * dest)
|
Handler(std::string * dest)
|
||||||
: fun([=](std::vector<std::string> ss) { *dest = ss[0]; })
|
: fun([dest](std::vector<std::string> ss) { *dest = ss[0]; })
|
||||||
, arity(1)
|
, arity(1)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
Handler(std::optional<std::string> * dest)
|
Handler(std::optional<std::string> * dest)
|
||||||
: fun([=](std::vector<std::string> ss) { *dest = ss[0]; })
|
: fun([dest](std::vector<std::string> ss) { *dest = ss[0]; })
|
||||||
, arity(1)
|
, arity(1)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Handler(T * dest, const T & val)
|
Handler(T * dest, const T & val)
|
||||||
: fun([=](std::vector<std::string> ss) { *dest = val; })
|
: fun([dest, val](std::vector<std::string> ss) { *dest = val; })
|
||||||
, arity(0)
|
, arity(0)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
template<class I>
|
template<class I>
|
||||||
Handler(I * dest)
|
Handler(I * dest)
|
||||||
: fun([=](std::vector<std::string> ss) {
|
: fun([dest](std::vector<std::string> ss) {
|
||||||
*dest = string2IntWithUnitPrefix<I>(ss[0]);
|
*dest = string2IntWithUnitPrefix<I>(ss[0]);
|
||||||
})
|
})
|
||||||
, arity(1)
|
, arity(1)
|
||||||
|
@ -114,7 +114,7 @@ protected:
|
||||||
|
|
||||||
template<class I>
|
template<class I>
|
||||||
Handler(std::optional<I> * dest)
|
Handler(std::optional<I> * dest)
|
||||||
: fun([=](std::vector<std::string> ss) {
|
: fun([dest](std::vector<std::string> ss) {
|
||||||
*dest = string2IntWithUnitPrefix<I>(ss[0]);
|
*dest = string2IntWithUnitPrefix<I>(ss[0]);
|
||||||
})
|
})
|
||||||
, arity(1)
|
, arity(1)
|
||||||
|
@ -130,7 +130,7 @@ protected:
|
||||||
* The `AddCompletions` that is passed is an interface to the state
|
* The `AddCompletions` that is passed is an interface to the state
|
||||||
* stored as part of the root command
|
* stored as part of the root command
|
||||||
*/
|
*/
|
||||||
typedef void CompleterFun(AddCompletions &, size_t, std::string_view);
|
using CompleterFun = void(AddCompletions &, size_t, std::string_view);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The closure type of the completion callback.
|
* The closure type of the completion callback.
|
||||||
|
@ -138,7 +138,7 @@ protected:
|
||||||
* This is what is actually stored as part of each Flag / Expected
|
* This is what is actually stored as part of each Flag / Expected
|
||||||
* Arg.
|
* Arg.
|
||||||
*/
|
*/
|
||||||
typedef std::function<CompleterFun> CompleterClosure;
|
using CompleterClosure = std::function<CompleterFun>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Description of flags / options
|
* Description of flags / options
|
||||||
|
@ -148,7 +148,7 @@ protected:
|
||||||
*/
|
*/
|
||||||
struct Flag
|
struct Flag
|
||||||
{
|
{
|
||||||
typedef std::shared_ptr<Flag> ptr;
|
using ptr = std::shared_ptr<Flag>;
|
||||||
|
|
||||||
std::string longName;
|
std::string longName;
|
||||||
std::set<std::string> aliases;
|
std::set<std::string> aliases;
|
||||||
|
@ -296,14 +296,14 @@ struct Command : virtual public Args
|
||||||
{
|
{
|
||||||
friend class MultiCommand;
|
friend class MultiCommand;
|
||||||
|
|
||||||
virtual ~Command() { }
|
virtual ~Command() = default;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Entry point to the command
|
* Entry point to the command
|
||||||
*/
|
*/
|
||||||
virtual void run() = 0;
|
virtual void run() = 0;
|
||||||
|
|
||||||
typedef int Category;
|
using Category = int;
|
||||||
|
|
||||||
static constexpr Category catDefault = 0;
|
static constexpr Category catDefault = 0;
|
||||||
|
|
||||||
|
@ -312,7 +312,7 @@ struct Command : virtual public Args
|
||||||
virtual Category category() { return catDefault; }
|
virtual Category category() { return catDefault; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::map<std::string, std::function<ref<Command>()>> Commands;
|
using Commands = std::map<std::string, std::function<ref<Command>()>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An argument parser that supports multiple subcommands,
|
* An argument parser that supports multiple subcommands,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue