broken.wip
[tfs.git] / tools / tf / WorkfoldCommand.cs
blob518e2c497a398a2c023e3c695329883027ae1b70
1 //
2 // WorkfoldCommand.cs
3 //
4 // Authors:
5 // Joel Reed (joelwreed@gmail.com)
6 //
8 //
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System;
30 using System.Collections.Generic;
31 using System.IO;
32 using System.Text;
33 using Microsoft.TeamFoundation.Client;
34 using Microsoft.TeamFoundation.VersionControl.Client;
36 [Command("workfold", "Map and unmap server paths to local folders.")]
37 class WorkfoldCommand : Command
39 public WorkfoldCommand(string[] arguments,
40 VersionControlServer vcs):
41 base(arguments, options, vcs)
45 public void CurrentWorkfolders(Workspace workspace)
47 Console.WriteLine("=".PadRight(WindowWidth, '='));
48 Console.WriteLine("Workspace: " + workspace.Name);
49 Console.WriteLine("Server : " + Options.Server);
51 foreach (WorkingFolder folder in workspace.Folders)
53 Console.WriteLine(" " + folder.ServerItem + " " + folder.LocalItem);
57 public void MapWorkfolder(Workspace workspace, string serverItem, string localItem)
59 List<WorkingFolder> folders = new List<WorkingFolder>(workspace.Folders);
60 folders.Add(new WorkingFolder(serverItem, localItem));
61 workspace.Update(workspace.Name, workspace.Comment, folders.ToArray());
64 public void UnmapWorkfolder(Workspace workspace, string item)
66 List<WorkingFolder> folders = new List<WorkingFolder>(workspace.Folders);
67 for (int i = 0; i < folders.Count; ++i)
69 WorkingFolder folder = folders[i];
71 if (item == folder.ServerItem || item == folder.LocalItem)
73 folders.RemoveAt(i);
74 break;
78 workspace.Update(workspace.Name, workspace.Comment, folders.ToArray());
81 public override void Run()
83 Workspace workspace = GetWorkspaceFromServer();
85 if (Arguments.Length < 2)
86 CurrentWorkfolders(workspace);
87 else if (Arguments.Length < 3)
89 if (!Options.Unmap)
90 Console.WriteLine("No-op");
91 else
92 UnmapWorkfolder(workspace, Arguments[1]);
94 else if (Arguments.Length == 3)
95 MapWorkfolder(workspace, Arguments[1], Arguments[2]);