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("labels", "Add a label or tag to an item.")]
37 class LabelsCommand
: Command
39 public LabelsCommand(string[] arguments
,
40 VersionControlServer vcs
):
41 base(arguments
, options
, vcs
)
45 public void BriefOutput(VersionControlLabel
[] labels
)
47 int maxName
= 9, maxOwner
= 5;
48 foreach (VersionControlLabel label
in labels
)
50 if (label
.Name
.Length
> maxName
) maxName
= label
.Name
.Length
;
52 // domain is stripped on output
53 int ownerNameLen
= label
.OwnerName
.Length
;
54 int slash
= label
.OwnerName
.IndexOf('\\');
55 if (-1 != slash
) ownerNameLen
= label
.OwnerName
.Length
- slash
;
57 if (ownerNameLen
> maxOwner
)
59 maxOwner
= ownerNameLen
;
63 int maxDate
= WindowWidth
- maxName
- maxOwner
- 3;
64 if (maxDate
< 0) maxDate
= 0;
66 string line
= String
.Format("{0} {1} {2}",
67 "Label".PadRight(maxName
),
68 "Owner".PadRight(maxOwner
),
69 "Date".PadRight(maxDate
));
70 Console
.WriteLine(line
);
72 line
= String
.Format("{0} {1} {2}",
73 "-".PadRight(maxName
, '-'),
74 "-".PadRight(maxOwner
, '-'),
75 "-".PadRight(maxDate
, '-'));
76 Console
.WriteLine(line
);
78 foreach (VersionControlLabel label
in labels
)
80 string date
= label
.LastModifiedDate
.ToString("d");
82 // domain is stripped on output
83 string ownerName
= label
.OwnerName
;
84 int slash
= label
.OwnerName
.IndexOf('\\');
87 ownerName
= label
.OwnerName
.Substring(slash
+1);
90 line
= String
.Format("{0} {1} {2}",
91 label
.Name
.PadRight(maxName
),
92 ownerName
.PadRight(maxOwner
),
94 Console
.WriteLine(line
);
98 public void DetailedOutput(VersionControlLabel
[] labels
)
102 foreach (VersionControlLabel label
in labels
)
106 Console
.WriteLine("=".PadRight(WindowWidth
, '='));
110 Console
.WriteLine("Label : " + label
.Name
);
111 Console
.WriteLine("Scope : " + label
.Scope
);
112 Console
.WriteLine("Owner : " + label
.OwnerName
);
113 Console
.WriteLine("Date : " + label
.LastModifiedDate
.ToString("F"));
114 Console
.WriteLine("Comment: " + label
.Comment
);
117 Console
.WriteLine("Changeset Item");
118 Console
.WriteLine("--------- {0}", new String('-', 70));
120 foreach (Item item
in label
.Items
)
122 Console
.WriteLine(item
.ChangesetId
+ " " + item
.ServerItem
);
129 public override void Run()
131 string labelName
= null;
132 if (Arguments
.Length
> 1)
134 labelName
= Arguments
[1];
137 bool detailed
= Options
.Format
.Equals("detailed", StringComparison
.InvariantCultureIgnoreCase
);
138 VersionControlLabel
[] labels
= VersionControlServer
.QueryLabels(labelName
, null, Owner
, detailed
);
140 if (detailed
) DetailedOutput(labels
);
141 else BriefOutput(labels
);