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 System
.Reflection
;
34 using Microsoft
.TeamFoundation
.Client
;
35 using Microsoft
.TeamFoundation
.VersionControl
.Client
;
36 using Mono
.GetOptions
;
38 [Command("help", "Describe the usage of this program or its subcommands.")]
39 class HelpCommand
: Command
41 [Option("List all commands without description", "L", "list")]
42 public bool OptionList
= false;
44 public HelpCommand(Driver driver
, string[] args
): base(driver
, args
)
48 public void ShowHelp()
50 Console
.WriteLine("usage: tf [subcommand] [arguments]");
52 Console
.WriteLine("Available subcommands:");
55 foreach (CommandAttribute attribute
in CommandRegistry
.Attributes
.Values
)
57 ShowCommandHelp(attribute
, " ");
61 public void ShowList()
63 foreach (string attribute
in CommandRegistry
.Attributes
.Keys
)
65 Console
.WriteLine(attribute
);
69 static public void ShowCommandHelp(CommandAttribute attribute
,
72 Console
.Write(indent
+ attribute
.Name
);
73 if (!String
.IsNullOrEmpty(attribute
.Alias
)) Console
.Write(" (alias {0})", attribute
.Alias
);
76 string description
= attribute
.Description
;
79 while (x
< description
.Length
)
81 int y
= Math
.Min(x
+ 60, description
.Length
);
82 int z
= description
.IndexOf(' ', y
) + 1;
83 if (z
== 0) z
= description
.Length
;
85 Console
.WriteLine(indent
+ " " + description
.Substring(x
, z
- x
));
92 public void ShowCommandHelp(string cmd
)
94 CommandAttribute attr
= CommandRegistry
.GetCommandAttribute(cmd
);
97 Console
.WriteLine("Unknown command: " + cmd
);
103 ShowCommandHelp(attr
, "");
104 Console
.WriteLine("Valid options:");
106 Type commandType
= CommandRegistry
.GetCommandType(cmd
);
107 foreach(MemberInfo mi
in commandType
.GetMembers())
109 if (mi
.MemberType
!= MemberTypes
.Field
) continue;
111 OptionAttribute
[] attribs
= mi
.GetCustomAttributes(typeof(OptionAttribute
), true) as OptionAttribute
[];
112 if (attribs
== null || attribs
.Length
== 0) continue;
114 foreach (OptionAttribute attrib
in attribs
)
116 Type fieldType
= ((FieldInfo
)mi
).FieldType
;
117 if (!String
.IsNullOrEmpty(attrib
.AlternateForm
))
119 string altform
= " /" + attrib
.AlternateForm
+ "";
120 if (fieldType
!= typeof(bool)) altform
+= ":ARG";
121 Console
.Write(altform
.PadRight(20));
124 Console
.Write("\t" + attrib
.ShortDescription
);
126 if (!String
.IsNullOrEmpty(attrib
.LongForm
))
128 Console
.Write(" (also /" + attrib
.LongForm
);
129 if (fieldType
!= typeof(bool)) Console
.Write(":ARG");
140 public override void Run()
148 if (Arguments
.Length
> 0)
149 ShowCommandHelp(Arguments
[0]);