Commit Diff


commit - a6864a68b3efe2c8a01ef1d058bf3977b6b91a3a
commit + c6d588b78684a2992b61c72b64f1bb3bab4b560c
blob - df2b1210a04405ec7b27f39602e074769b7cff86
blob + 4746965b3fd5d0df1e8a79c035b8b42c798b661e
--- gotd/libexec/got-notify-email/got-notify-email.c
+++ gotd/libexec/got-notify-email/got-notify-email.c
@@ -16,6 +16,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
+#include <getopt.h>
 
 #include "got_error.h"
 #include "got_repository.h"
@@ -24,27 +25,84 @@
 __dead static void
 usage(void)
 {
-	fprintf(stderr, "usage: %s [repo-path]\n", getprogname());
+	fprintf(stderr, "usage: %s [-ds] [-f sender ] [-r repo-path] "
+	    "[-R responder] recipient\n", getprogname());
 	exit(1);
 }
 
+static int
+validate_email_addr(const char *addr)
+{
+	return 0;
+}
+
+static char *
+set_default_fromaddr(void)
+{
+	return NULL;
+}
+
+static const struct got_error *
+notify(struct got_repository *repo, const char *fromaddr,
+    const char *recipient, char *replytoaddr, int shortlog,
+    int with_diff)
+{
+	return got_error(GOT_ERR_NOT_IMPL);
+}
+
 int
 main(int argc, char *argv[])
 {
 	const struct got_error *error;
-	char *repo_path;
 	struct got_repository *repo = NULL;
-	int *pack_fds = NULL;
+	int ch, *pack_fds = NULL;
+	char *repo_path = NULL, *fromaddr = NULL;
+	char *recipient = NULL, *replytoaddr = NULL;
+	int shortlog = 0, with_diff = 0;
 
+	while ((ch = getopt(argc, argv, "df:r:R:s")) != -1) {
+		switch (ch) {
+		case 'd':
+			with_diff = 1;
+			break;
+		case 'f':
+			fromaddr = optarg;
+			break;
+		case 'r':
+			repo_path = optarg;
+			break;
+		case 'R':
+			replytoaddr = optarg;
+			break;
+		case 's':
+			shortlog = 1;
+			break;
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+
 	if (argc != 2)
 		usage();
 
+	recipient = argv[1];
+
+	if (!validate_email_addr(recipient))
+		goto done;
+
+	if (fromaddr == NULL)
+		fromaddr = set_default_fromaddr();
+
 	error = got_repo_pack_fds_open(&pack_fds);
 	if (error != NULL)
 		goto done;
 	error = got_repo_open(&repo, repo_path, NULL, pack_fds);
 	if (error)
 		goto done;
+
+	error = notify(repo, fromaddr, recipient, replytoaddr, shortlog,
+	    with_diff);
 done:
 	if (pack_fds) {
 		const struct got_error *pack_err =