|
|
@@ -25,15 +25,10 @@ template <typename T, size_t N> static T parse(char const * const (&argv)[N]) {
|
|
|
|
|
|
program::detail::Any g_action;
|
|
|
|
|
|
-template <typename Args, typename Action>
|
|
|
-int typed_main(Args const &, Action const & action) {
|
|
|
- g_action = program::detail::Any(&action);
|
|
|
- return 0;
|
|
|
-}
|
|
|
-
|
|
|
-template <typename Args, typename Action, typename SubAction>
|
|
|
-int typed_main(Args const &, Action const &, SubAction const & action) {
|
|
|
- g_action = program::detail::Any(&action);
|
|
|
+template <typename Arg, typename... Args>
|
|
|
+int typed_main(Arg const &arg, Args const &...args) {
|
|
|
+ auto const &last = std::get<sizeof...(Args)>(std::forward_as_tuple(arg, args...));
|
|
|
+ g_action = program::detail::Any(&last);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
@@ -103,6 +98,13 @@ struct Git : program::Arguments<Git> {
|
|
|
Remote remote = action("remote");
|
|
|
};
|
|
|
|
|
|
+struct GitPlug : program::Arguments<GitPlug> {
|
|
|
+ PROGRAM_ARGS_INVOKE_WITH_DEFAULT(*this, commit, checkout);
|
|
|
+
|
|
|
+ Commit commit = action("commit");
|
|
|
+ Checkout checkout = action("checkout");
|
|
|
+};
|
|
|
+
|
|
|
std::string Push::_remote() const {
|
|
|
if (Git const * git = Arguments::parent<Git>()) { return git->pwd; }
|
|
|
return "";
|
|
|
@@ -152,3 +154,10 @@ TEST(ActionTest, CanStoreDefaultAction) {
|
|
|
program::ArgumentTestHelper::main(git);
|
|
|
EXPECT_THAT(g_action.get<Show>(), NotNull());
|
|
|
}
|
|
|
+
|
|
|
+TEST(ActionTest, DefaultActionCanBeSelf) {
|
|
|
+ GitPlug git = parse<GitPlug>({""});
|
|
|
+
|
|
|
+ program::ArgumentTestHelper::main(git);
|
|
|
+ EXPECT_THAT(g_action.get<GitPlug>(), NotNull());
|
|
|
+}
|