[darwinbuild-changes] [704] branches/PR-7598640

source_changes at macosforge.org source_changes at macosforge.org
Thu Feb 11 21:17:03 PST 2010


Revision: 704
          http://trac.macosforge.org/projects/darwinbuild/changeset/704
Author:   wsiegrist at apple.com
Date:     2010-02-11 21:17:03 -0800 (Thu, 11 Feb 2010)
Log Message:
-----------
Allow for >1 argument to subcommands

Modified Paths:
--------------
    branches/PR-7598640/darwinup/main.cpp
    branches/PR-7598640/testing/darwinup/run-tests.sh

Modified: branches/PR-7598640/darwinup/main.cpp
===================================================================
--- branches/PR-7598640/darwinup/main.cpp	2010-02-12 03:47:32 UTC (rev 703)
+++ branches/PR-7598640/darwinup/main.cpp	2010-02-12 05:17:03 UTC (rev 704)
@@ -119,7 +119,8 @@
 	}
 	argc -= optind;
 	argv += optind;
-
+	if (argc == 0) usage(progname);
+	
 	int res = 0;
 
 	if (!path) {
@@ -128,44 +129,54 @@
 		
 	Depot* depot = new Depot(path);
 		
-	if (argc == 2 && strcmp(argv[0], "install") == 0) {
-		if (depot->initialize(true)) exit(13);
-		res = depot->install(argv[1]);
-	} else if (argc == 2 && strcmp(argv[0], "upgrade") == 0) {
-		if (depot->initialize(true)) exit(14);
-		// find most recent matching archive by name
-		Archive* old = depot->get_archive(basename(argv[1]));
-		if (!old) {
-			fprintf(stderr, "Error: unable to find a matching root to upgrade.\n");
-			res = 5;
+	// commands with no arguments
+	if (argc == 1) {
+		if (strcmp(argv[0], "list") == 0) {
+			res = depot->initialize(false);
+			if (res == -2) {
+				fprintf(stdout, "Nothing has been installed yet.\n");
+				exit(0);
+			}
+			if (res == 0) depot->list();
+		} else if (strcmp(argv[0], "dump") == 0) {
+			if (depot->initialize(false)) exit(11);
+			depot->dump();
+		} else {
+			usage(progname);
 		}
-		// install new archive
-		if (res == 0) res = depot->install(argv[1]);
-		// uninstall old archive
-		if (res == 0) res = depot->uninstall(old);
-	} else if (argc == 1 && strcmp(argv[0], "list") == 0) {
-		res = depot->initialize(false);
-		if (res == -2) {
-			fprintf(stdout, "Nothing has been installed yet.\n");
-			exit(0);
+	}
+	
+	// loop over arguments
+	for (int i = 1; i < argc; i++) {
+		if (strcmp(argv[0], "install") == 0) {
+			if (i==1 && depot->initialize(true)) exit(13);
+			res = depot->install(argv[i]);
+		} else if (strcmp(argv[0], "upgrade") == 0) {
+			if (i==1 && depot->initialize(true)) exit(14);
+			// find most recent matching archive by name
+			Archive* old = depot->get_archive(basename(argv[i]));
+			if (!old) {
+				fprintf(stderr, "Error: unable to find a matching root to upgrade.\n");
+				res = 5;
+			}
+			// install new archive
+			if (res == 0) res = depot->install(argv[i]);
+			// uninstall old archive
+			if (res == 0) res = depot->uninstall(old);
+		} else if (strcmp(argv[0], "files") == 0) {
+			if (i==1 && depot->initialize(false)) exit(12);
+			res = depot->process_archive(argv[0], argv[i]);
+		} else if (strcmp(argv[0], "uninstall") == 0) {
+			if (i==1 && depot->initialize(true)) exit(15);
+			res = depot->process_archive(argv[0], argv[i]);
+		} else if (strcmp(argv[0], "verify") == 0) {
+			if (i==1 && depot->initialize(true)) exit(16);
+			res = depot->process_archive(argv[0], argv[i]);
+		} else {
+			usage(progname);
 		}
-		if (res == 0) depot->list();
-	} else if (argc == 1 && strcmp(argv[0], "dump") == 0) {
-		if (depot->initialize(false)) exit(11);
-		depot->dump();
-	} else if (argc == 2 && strcmp(argv[0], "files") == 0) {
-		if (depot->initialize(false)) exit(12);
-		res = depot->process_archive(argv[0], argv[1]);
-	} else if (argc == 2 && strcmp(argv[0], "uninstall") == 0) {
-		if (depot->initialize(true)) exit(15);
-		res = depot->process_archive(argv[0], argv[1]);
-	} else if (argc == 2 && strcmp(argv[0], "verify") == 0) {
-		if (depot->initialize(true)) exit(16);
-		res = depot->process_archive(argv[0], argv[1]);
-	} else {
-		usage(progname);
 	}
-
+	
 	free(path);
 	exit(res);
 	return res;

Modified: branches/PR-7598640/testing/darwinup/run-tests.sh
===================================================================
--- branches/PR-7598640/testing/darwinup/run-tests.sh	2010-02-12 03:47:32 UTC (rev 703)
+++ branches/PR-7598640/testing/darwinup/run-tests.sh	2010-02-12 05:17:03 UTC (rev 704)
@@ -47,6 +47,18 @@
 	$DIFF $ORIG $DEST 2>&1
 done
 
+echo "========== TEST: Multiple argument test ==========";
+darwinup -vv -p $DEST install $PREFIX/root{,2,3}
+LINES=$(darwinup -p $DEST list | wc -l)
+if [ $LINES -lt 5 ]; then
+	echo "Failed multiple argument test."
+	exit 1;
+fi
+darwinup -vv -p $DEST uninstall all
+echo "DIFF: diffing original test files to dest (should be no diffs) ..."
+$DIFF $ORIG $DEST 2>&1
+
+
 echo "========== TEST: Trying all roots at once, uninstall in reverse ==========";
 for R in $ROOTS;
 do
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/darwinbuild-changes/attachments/20100211/8c4f5605/attachment-0001.html>


More information about the darwinbuild-changes mailing list