public bool Run(System.IO.DirectoryInfo workingDirectory, object options) { StashListVerbOptions localOptions = options as StashListVerbOptions; Printer.EnableDiagnostics = localOptions.Verbose; Area ws = Area.Load(workingDirectory); if (ws == null) { return(false); } if (localOptions.Remote != null) { if (localOptions.Remote == string.Empty) { localOptions.Remote = "default"; } LocalState.RemoteConfig config = null; if (ws != null) { config = ws.GetRemote(string.IsNullOrEmpty(localOptions.Remote) ? "default" : localOptions.Remote); } if (config != null) { localOptions.Remote = config.URL; } Printer.PrintMessage("Querying stashes on remote #b#{0}##.", localOptions.Remote); Network.IRemoteClient client = ws.Connect(localOptions.Remote, false); var stashes = client.ListStashes(localOptions.Name); if (stashes.Count == 0) { Printer.PrintMessage("Remote vault has no stashes{0}.", (localOptions.Name == null || localOptions.Name.Count == 0) ? "" : " matching the query name."); } else { Printer.PrintMessage("Remote vault has #b#{0}## stash{1} {2}:", stashes.Count, stashes.Count == 1 ? "" : "es", (localOptions.Name == null || localOptions.Name.Count == 0) ? "available" : " matching the query name."); foreach (var x in Enumerable.Reverse(stashes)) { Printer.PrintMessage(" #b#{0}##: #q#{4}##\n {1} - by {2} on #q#{3}##", x.Author + "-" + x.Key, string.IsNullOrEmpty(x.Name) ? "(no name)" : ("\"" + x.Name + "\""), x.Author, x.Time.ToLocalTime(), x.GUID); } } client.Close(); return(true); } if (localOptions.Name == null || localOptions.Name.Count == 0) { var stashes = ws.ListStashes(); if (stashes.Count == 0) { Printer.PrintMessage("Vault has no stashes."); } else { Printer.PrintMessage("Vault has #b#{0}## stash{1} available:", stashes.Count, stashes.Count == 1 ? "" : "es"); foreach (var x in Enumerable.Reverse(stashes)) { Printer.PrintMessage(" #b#{0}##: {5} - #q#{4}##\n {1} - by {2} on #q#{3}##", x.Author + "-" + x.Key, string.IsNullOrEmpty(x.Name) ? "(no name)" : ("\"" + x.Name + "\""), x.Author, x.Time.ToLocalTime(), x.GUID, Versionr.Utilities.Misc.FormatSizeFriendly(x.File.Length)); } } } else { foreach (var n in localOptions.Name) { var stash = LookupStash(ws, n); if (stash != null) { if (localOptions.DisplayDiff) { Printer.PrintMessage("{1} patch for stash #b#{2}## ({0})", stash.GUID, string.IsNullOrEmpty(localOptions.PatchFile) ? "Showing" : "Generating", stash.Key); } else { Printer.PrintMessage("Showing stash #b#{1}## ({0})", stash.GUID, stash.Key); } Stream baseStream = null; if (string.IsNullOrEmpty(localOptions.PatchFile)) { baseStream = new MemoryStream(); } else { baseStream = File.Open(localOptions.PatchFile, FileMode.Create, FileAccess.ReadWrite); } ws.DisplayStashOperations(stash); if (localOptions.DisplayDiff) { using (StreamWriter sw = new StreamWriter(baseStream)) { ws.StashToPatch(sw, stash); sw.Flush(); baseStream.Position = 0; if (string.IsNullOrEmpty(localOptions.PatchFile)) { using (TextReader tr = new StreamReader(baseStream)) { string[] patchLines = tr.ReadToEnd().Split('\n'); foreach (var x in patchLines) { if (x.StartsWith("@@")) { Printer.PrintMessage("#c#{0}##", Printer.Escape(x)); } else if (x.StartsWith("+++")) { Printer.PrintMessage("#b#{0}##", Printer.Escape(x)); } else if (x.StartsWith("---")) { Printer.PrintMessage("#b#{0}##", Printer.Escape(x)); } else if (x.StartsWith("-")) { Printer.PrintMessage("#e#{0}##", Printer.Escape(x)); } else if (x.StartsWith("+")) { Printer.PrintMessage("#s#{0}##", Printer.Escape(x)); } else { Printer.PrintMessage(Printer.Escape(x)); } } } } } } } } } return(true); }
public bool Run(System.IO.DirectoryInfo workingDirectory, object options) { RemoteCommandVerbOptions localOptions = options as RemoteCommandVerbOptions; Printer.EnableDiagnostics = localOptions.Verbose; Network.Client client = null; Area ws = null; Tuple<bool, string, int, string> parsedRemoteName = null; if (!string.IsNullOrEmpty(localOptions.Remote)) { if (parsedRemoteName == null) parsedRemoteName = TryParseRemoteName(localOptions.Remote); localOptions.Host = parsedRemoteName.Item2; if (parsedRemoteName.Item3 != -1) localOptions.Port = parsedRemoteName.Item3; localOptions.Module = parsedRemoteName.Item4; } if (NeedsWorkspace) { ws = Area.Load(workingDirectory, Headless); if (ws == null) { Printer.Write(Printer.MessageType.Error, string.Format("#x#Error:##\n The current directory #b#`{0}`## is not part of a vault.\n", workingDirectory.FullName)); return false; } client = new Network.Client(ws); } else { if (NeedsNoWorkspace) { string subdir = localOptions.Name; if (string.IsNullOrEmpty(subdir) && !string.IsNullOrEmpty(localOptions.Module)) subdir = localOptions.Module; if (!string.IsNullOrEmpty(subdir)) { System.IO.DirectoryInfo info; try { info = new System.IO.DirectoryInfo(System.IO.Path.Combine(workingDirectory.FullName, subdir)); } catch { Printer.PrintError("#e#Error - invalid subdirectory \"{0}\"##", subdir); return false; } Printer.PrintMessage("Target directory: #b#{0}##.", info); workingDirectory = info; } try { ws = Area.Load(workingDirectory, Headless); if (ws != null) { CloneVerbOptions cloneOptions = options as CloneVerbOptions; if (cloneOptions != null && cloneOptions.QuietFail) { Printer.PrintMessage("Directory already contains a vault. Skipping."); return false; } Printer.PrintError("This command cannot function with an active Versionr vault."); return false; } } catch { } } client = new Client(workingDirectory); } TargetDirectory = workingDirectory; bool requireRemoteName = false; if (string.IsNullOrEmpty(localOptions.Host) || localOptions.Port == -1) requireRemoteName = true; LocalState.RemoteConfig config = null; if (ws != null) { if (requireRemoteName) config = ws.GetRemote(string.IsNullOrEmpty(localOptions.Name) ? "default" : localOptions.Name); if (UpdateRemoteTimestamp && config != null) ws.UpdateRemoteTimestamp(config); } if (config == null && requireRemoteName) { if (parsedRemoteName != null && parsedRemoteName.Item1 == false) { Printer.PrintError("You must specify either a host and port or a remote name."); return false; } } if (config == null) config = new LocalState.RemoteConfig() { Host = localOptions.Host, Port = localOptions.Port, Module = localOptions.Module }; if (!client.Connect(config.Host, config.Port, config.Module, RequiresWriteAccess)) { Printer.PrintError("Couldn't connect to server!"); return false; } bool result = RunInternal(client, localOptions); client.Close(); return result; }
public bool Run(System.IO.DirectoryInfo workingDirectory, object options) { RemoteCommandVerbOptions localOptions = options as RemoteCommandVerbOptions; Printer.EnableDiagnostics = localOptions.Verbose; IRemoteClient client = null; Area ws = null; if (NeedsWorkspace) { ws = Area.Load(workingDirectory, Headless); if (ws == null) { Printer.Write(Printer.MessageType.Error, string.Format("#x#Error:##\n The current directory #b#`{0}`## is not part of a vault.\n", workingDirectory.FullName)); return(false); } } TargetDirectory = workingDirectory; bool requireRemoteName = false; LocalState.RemoteConfig config = null; if (ws != null) { config = ws.GetRemote(string.IsNullOrEmpty(localOptions.Remote) ? "default" : localOptions.Remote); if (UpdateRemoteTimestamp && config != null) { ws.UpdateRemoteTimestamp(config); } } if (config == null && string.IsNullOrEmpty(localOptions.Remote)) { requireRemoteName = true; } if (config == null && requireRemoteName) { Printer.PrintError("You must specify either a remote server or name."); return(false); } if (config == null) { config = new LocalState.RemoteConfig() { Module = localOptions.Remote } } ; if (ws == null) { // No workspace; must use Versionr Client client = new Client(workingDirectory); if (!((Client)client).Connect(config.URL, RequiresWriteAccess)) { client = null; } } else { client = ws.Connect(config.URL, RequiresWriteAccess); URL = config.URL; } if (client == null || !client.Connected) { Printer.PrintError("Couldn't connect to server:## #b#{0}##", config.URL); return(false); } bool result = RunInternal(client, localOptions); client.Close(); return(result); }