Selaa lähdekoodia

added "update" command to update a single lib

Nicolas Cannasse 13 vuotta sitten
vanhempi
commit
b478e8fe3a
1 muutettua tiedostoa jossa 39 lisäystä ja 29 poistoa
  1. 39 29
      std/tools/haxelib/Main.hx

+ 39 - 29
std/tools/haxelib/Main.hx

@@ -111,6 +111,7 @@ class Main {
 		addCommand("install",install,"install a given library");
 		addCommand("install",install,"install a given library");
 		addCommand("list",list,"list all installed libraries",false);
 		addCommand("list",list,"list all installed libraries",false);
 		addCommand("upgrade",upgrade,"upgrade all installed libraries");
 		addCommand("upgrade",upgrade,"upgrade all installed libraries");
+		addCommand("update",update,"update a single library");
 		addCommand("remove",remove,"remove a given library/version",false);
 		addCommand("remove",remove,"remove a given library/version",false);
 		addCommand("set",set,"set the current version for a library",false);
 		addCommand("set",set,"set the current version for a library",false);
 		addCommand("search",search,"list libraries matching a word");
 		addCommand("search",search,"list libraries matching a word");
@@ -619,44 +620,53 @@ class Main {
 	}
 	}
 
 
 	function upgrade() {
 	function upgrade() {
-		var rep = getRepository();
-		var prompt = true;
-		var update = false;
-		for( p in sys.FileSystem.readDirectory(rep) ) {
-			if( p.charAt(0) == "." || !sys.FileSystem.isDirectory(rep+"/"+p) )
+		var state = { rep : getRepository(), prompt : true, updated : false };
+		for( p in sys.FileSystem.readDirectory(state.rep) ) {
+			if( p.charAt(0) == "." || !sys.FileSystem.isDirectory(state.rep+"/"+p) )
 				continue;
 				continue;
 			var p = Datas.unsafe(p);
 			var p = Datas.unsafe(p);
 			print("Checking " + p);
 			print("Checking " + p);
-			if (sys.FileSystem.exists(rep + "/" + p + "/git") && sys.FileSystem.isDirectory(rep + "/" + p + "/git"))
-			{
-				var oldCwd = Sys.getCwd();
-				Sys.setCwd(rep + "/" + p + "/git");
-				Sys.command("git pull");
-				// TODO: update haxelib.xml version?
-				Sys.setCwd(oldCwd);
-			}
-			else
-			{
-				var inf = try site.infos(p) catch( e : Dynamic ) { Sys.println(e); continue; };
-				if( !sys.FileSystem.exists(rep+Datas.safe(p)+"/"+Datas.safe(inf.curversion)) ) {
-					if( prompt )
-						switch ask("Upgrade "+p+" to "+inf.curversion) {
-						case Yes:
-						case Always: prompt = false;
-						case No: continue;
-						}
-					doInstall(p,inf.curversion,true);
-					update = true;
-				} else
-					setCurrent(p, inf.curversion, true);
-			}
+			doUpdate(p,state);
 		}
 		}
-		if( update )
+		if( state.updated )
 			print("Done");
 			print("Done");
 		else
 		else
 			print("All libraries are up-to-date");
 			print("All libraries are up-to-date");
 	}
 	}
 
 
+	function doUpdate( p : String, state ) {
+		var rep = state.rep;
+		if( sys.FileSystem.exists(rep + "/" + p + "/git") && sys.FileSystem.isDirectory(rep + "/" + p + "/git") ) {
+			var oldCwd = Sys.getCwd();
+			Sys.setCwd(rep + "/" + p + "/git");
+			Sys.command("git pull");
+			// TODO: update haxelib.xml version?
+			Sys.setCwd(oldCwd);
+		} else {
+			var inf = try site.infos(p) catch( e : Dynamic ) { Sys.println(e); return; };
+			if( !sys.FileSystem.exists(rep+Datas.safe(p)+"/"+Datas.safe(inf.curversion)) ) {
+				if( state.prompt )
+					switch ask("Upgrade "+p+" to "+inf.curversion) {
+					case Yes:
+					case Always: state.prompt = false;
+					case No:
+						return;
+					}
+				doInstall(p,inf.curversion,true);
+				state.updated = true;
+			} else
+				setCurrent(p, inf.curversion, true);
+		}
+	}
+
+	function update() {
+		var prj = param("Library");
+		var state = { rep : getRepository(), prompt : false, updated : false };
+		doUpdate(prj,state);
+		if( !state.updated )
+			print(prj + " is up to date");
+	}
+
 	function deleteRec(dir) {
 	function deleteRec(dir) {
 		for( p in sys.FileSystem.readDirectory(dir) ) {
 		for( p in sys.FileSystem.readDirectory(dir) ) {
 			var path = dir+"/"+p;
 			var path = dir+"/"+p;