|
|
@@ -31,6 +31,12 @@ int typed_main(Args const &, Action const & 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);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
struct Checkout : program::Arguments<Checkout> {
|
|
|
using Arguments::Arguments;
|
|
|
std::string commitish = argument(0, "commit-ish");
|
|
|
@@ -50,6 +56,27 @@ private:
|
|
|
std::string _remote() const;
|
|
|
};
|
|
|
|
|
|
+struct SetUrl : program::Arguments<SetUrl> {
|
|
|
+ using Arguments::Arguments;
|
|
|
+ bool push = flag("push") = false;
|
|
|
+ std::string name = argument(0, "name");
|
|
|
+ std::string new_url = argument(1, "newurl");
|
|
|
+ std::string old_url = argument(2, "oldurl") = "";
|
|
|
+};
|
|
|
+
|
|
|
+struct Show : program::Arguments<Show> {
|
|
|
+ using Arguments::Arguments;
|
|
|
+ bool use_cached = flag('n') = false;
|
|
|
+};
|
|
|
+
|
|
|
+struct Remote : public program::Arguments<Remote> {
|
|
|
+ PROGRAM_ARGS_INVOKE_WITH_DEFAULT(show, show, set_url);
|
|
|
+
|
|
|
+ bool verbose = flag('v') = false;
|
|
|
+ SetUrl set_url = action("set-url");
|
|
|
+ Show show = action("show");
|
|
|
+};
|
|
|
+
|
|
|
struct Bad1 : program::Arguments<Bad1> {
|
|
|
using Arguments::Arguments;
|
|
|
|
|
|
@@ -65,7 +92,7 @@ struct Bad2 : program::Arguments<Bad2> {
|
|
|
};
|
|
|
|
|
|
struct Git : program::Arguments<Git> {
|
|
|
- using Arguments::Arguments;
|
|
|
+ PROGRAM_ARGS_INVOKE(commit, checkout, push, remote);
|
|
|
|
|
|
std::string pwd = option('C');
|
|
|
bool verbose = flag("verbose", 'v');
|
|
|
@@ -73,10 +100,9 @@ struct Git : program::Arguments<Git> {
|
|
|
Commit commit = action("commit");
|
|
|
Checkout checkout = action("checkout");
|
|
|
Push push = action("push");
|
|
|
+ Remote remote = action("remote");
|
|
|
};
|
|
|
|
|
|
-PROGRAM_ARGS_INVOKE(Git, commit, checkout, push)
|
|
|
-
|
|
|
std::string Push::_remote() const {
|
|
|
if (Git const * git = Arguments::parent<Git>()) { return git->pwd; }
|
|
|
return "";
|
|
|
@@ -104,3 +130,25 @@ TEST(ActionTest, CanFetchParentInfo) {
|
|
|
Git git = parse<Git>({"", "-C", "./submodules/X", "push"});
|
|
|
EXPECT_THAT(git.push.remote, "./submodules/X");
|
|
|
}
|
|
|
+
|
|
|
+TEST(ActionTest, ReturnsFailureOnNoAction) {
|
|
|
+ Git git = parse<Git>({""});
|
|
|
+
|
|
|
+ EXPECT_THAT(program::ArgumentTestHelper::main(git), 1);
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ActionTest, CanRecursivelyPerformActions) {
|
|
|
+ Git git = parse<Git>({"", "remote", "-v", "show", "-n"});
|
|
|
+ EXPECT_TRUE(git.remote.verbose);
|
|
|
+ EXPECT_TRUE(git.remote.show.use_cached);
|
|
|
+
|
|
|
+ program::ArgumentTestHelper::main(git);
|
|
|
+ EXPECT_THAT(g_action.get<Show>(), NotNull());
|
|
|
+}
|
|
|
+
|
|
|
+TEST(ActionTest, CanStoreDefaultAction) {
|
|
|
+ Git git = parse<Git>({"", "remote"});
|
|
|
+
|
|
|
+ program::ArgumentTestHelper::main(git);
|
|
|
+ EXPECT_THAT(g_action.get<Show>(), NotNull());
|
|
|
+}
|