2 // WorkspacesCommand.cs
5 // Joel Reed (joelwreed@gmail.com)
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:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
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.
30 using System
.Collections
.Generic
;
33 using Microsoft
.TeamFoundation
.Client
;
34 using Microsoft
.TeamFoundation
.VersionControl
.Client
;
36 [Command("workspaces", "List workspaces in server repository.")]
37 class WorkspacesCommand
: Command
39 public WorkspacesCommand(driver
): base(driver
)
43 public void BriefOutput(Workspace
[] workspaces
)
45 int maxName
= 9, maxComputer
= 8, maxOwner
= 5;
46 foreach (Workspace workspace
in workspaces
)
48 if (workspace
.Name
.Length
> maxName
) maxName
= workspace
.Name
.Length
;
49 if (workspace
.Computer
.Length
> maxComputer
) maxComputer
= workspace
.Computer
.Length
;
51 // domain is stripped on output
52 int ownerNameLen
= workspace
.OwnerName
.Length
;
53 int slash
= workspace
.OwnerName
.IndexOf('\\');
54 if (-1 != slash
) ownerNameLen
= workspace
.OwnerName
.Length
- slash
;
56 if (ownerNameLen
> maxOwner
)
58 maxOwner
= ownerNameLen
;
62 int maxComment
= WindowWidth
- maxName
- maxComputer
- maxOwner
- 3;
63 if (maxComment
< 0) maxComment
= 0;
65 string line
= String
.Format("{0} {1} {2} {3}",
66 "Workspace".PadRight(maxName
),
67 "Owner".PadRight(maxOwner
),
68 "Computer".PadRight(maxComputer
),
70 Console
.WriteLine(line
);
72 line
= String
.Format("{0} {1} {2} {3}",
73 "-".PadRight(maxName
, '-'),
74 "-".PadRight(maxOwner
, '-'),
75 "-".PadRight(maxComputer
, '-'),
76 "-".PadRight(maxComment
, '-'));
77 Console
.WriteLine(line
);
79 foreach (Workspace workspace
in workspaces
)
82 if (workspace
.Comment
.Length
> maxComment
)
83 comment
= workspace
.Comment
.Remove(maxComment
);
85 comment
= workspace
.Comment
;
87 // domain is stripped on output
88 string ownerName
= workspace
.OwnerName
;
89 int slash
= workspace
.OwnerName
.IndexOf('\\');
92 ownerName
= workspace
.OwnerName
.Substring(slash
+1);
95 line
= String
.Format("{0} {1} {2} {3}",
96 workspace
.Name
.PadRight(maxName
),
97 ownerName
.PadRight(maxOwner
),
98 workspace
.Computer
.PadRight(maxComputer
),
100 Console
.WriteLine(line
);
104 public void DetailedOutput(Workspace
[] workspaces
)
108 foreach (Workspace workspace
in workspaces
)
110 if (!first
) Console
.WriteLine();
113 Console
.WriteLine("=".PadRight(WindowWidth
, '='));
114 Console
.WriteLine("Workspace: " + workspace
.Name
);
115 Console
.WriteLine("Owner : " + workspace
.OwnerName
);
116 Console
.WriteLine("Computer : " + workspace
.Computer
);
117 Console
.WriteLine("Comment : " + workspace
.Comment
);
118 Console
.WriteLine("Server : " + Options
.Server
);
121 Console
.WriteLine("Working folders:");
123 foreach (WorkingFolder folder
in workspace
.Folders
)
125 Console
.WriteLine(" " + folder
.ServerItem
+ " " + folder
.LocalItem
);
130 public override void Run()
132 Workspace
[] workspaces
= VersionControlServer
.QueryWorkspaces(null, Owner
, Computer
);
134 if (workspaces
.Length
== 0)
136 Console
.WriteLine("No workspace matching {0} on computer {1} found in Team Foundation Server.",
138 Environment
.Exit(-1);
141 bool detailed
= Options
.Format
.Equals("detailed", StringComparison
.InvariantCultureIgnoreCase
);
142 if (detailed
) DetailedOutput(workspaces
);
143 else BriefOutput(workspaces
);