1 <Type Name="Command" FullName="Mono.Options.Command">
2 <TypeSignature Language="C#" Value="public class Command" />
3 <TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit Command extends System.Object" />
5 <AssemblyName>Mono.Options</AssemblyName>
6 <AssemblyVersion>0.2.3.0</AssemblyVersion>
8 <ThreadingSafetyStatement>
9 Public <c>static</c> members of this type are thread safe.
10 Any instance members are not guaranteed to be thread safe.
11 </ThreadingSafetyStatement>
13 <BaseTypeName>System.Object</BaseTypeName>
18 Represents a program command.
22 Many command-line utilities are <i>suites</i> of commands, with a single
23 "outer" command and multiple commands. Examples of this style of
24 utility includes <b>git</b>, <b>svn</b>, and <b>mdoc</b>.
27 A <c>Command</c> represents a specific command in such a suite.
28 It has a <see cref="P:Mono.Options.Command.Name" /> which is the
29 command name for invocation purposes, optional help text through
30 the <see cref="P:Mono.Options.Command.Help" /> property, an optional
31 <see cref="T:Mono.Options.OptionSet" /> accessible through the
32 <see cref="P:Mono.Options.Command.Options" /> property for command-line
33 parsing, and two ways to have code executed when a command is
34 invoked: the <see cref="P:Mono.Options.Command.Run" /> property and
35 the <see cref="M:Mono.Options.Command.Invoke" /> method.
40 <Member MemberName=".ctor">
41 <MemberSignature Language="C#" Value="public Command (string name, string help = null);" />
42 <MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(string name, string help) cil managed" />
43 <MemberType>Constructor</MemberType>
45 <AssemblyVersion>0.2.3.0</AssemblyVersion>
48 <Parameter Name="name" Type="System.String" />
49 <Parameter Name="help" Type="System.String" />
53 A <see cref="T:System.String" /> which is the command name.
56 A <see cref="T:System.String" /> which is the command help text.
59 Creates and initializes a new instance of the <c>Command</c> class.
63 This constructor initializes the
64 <see cref="P:Mono.Options.Command.Name" /> property of the new
65 instance using <paramref name="name" /> and initializes the
66 <see cref="P:Mono.Options.Command.Help" /> property of the new
67 instance using <paramref name="help" />.
70 <exception cref="T:System.ArgumentNullException">
71 <paramref name="name" /> is <see langword="null" />.
75 <Member MemberName="CommandSet">
76 <MemberSignature Language="C#" Value="public Mono.Options.CommandSet CommandSet { get; }" />
77 <MemberSignature Language="ILAsm" Value=".property instance class Mono.Options.CommandSet CommandSet" />
78 <MemberType>Property</MemberType>
80 <AssemblyVersion>0.2.3.0</AssemblyVersion>
83 <ReturnType>Mono.Options.CommandSet</ReturnType>
87 A <see cref="T:Mono.Options.CommandSet" /> instance which owns the
91 A <see cref="T:Mono.Options.CommandSet" /> instance which owns the
96 A <c>Command</c> instance may belong to only one
97 <see cref="T:Mono.Options.CommandSet" /> instance.
98 The <c>CommandSet</c> property is set upon calling
99 <see cref="M:Mono.Options.CommandSet.Add(Mono.Options.Command)" />.
102 If the <c>Command</c> instance has not yet been added to a
103 <c>CommandSet</c>, then this property is <see langword="null" />.
106 Use the <c>CommandSet</c> instance from either the
107 <see cref="P:Mono.Options.Command.Run" /> property or an overridden
108 <see cref="M:Mono.Options.Command.Invoke" /> method to access
109 localization facilities through
110 <see cref="P:Mono.Options.CommandSet.MessageLocalizer" />, the
111 preferred message output stream through
112 <see cref="P:Mono.Options.CommandSet.Out" />, and other features.
117 <Member MemberName="Help">
118 <MemberSignature Language="C#" Value="public string Help { get; }" />
119 <MemberSignature Language="ILAsm" Value=".property instance string Help" />
120 <MemberType>Property</MemberType>
122 <AssemblyVersion>0.2.3.0</AssemblyVersion>
125 <ReturnType>System.String</ReturnType>
129 A short, one-line, description of the <c>Command</c>.
132 A <see cref="T:System.String" /> containing the optional help text
133 of the <c>Command</c>.
137 The <c>Help</c> property text is shown when the <c>help</c>
143 <Member MemberName="Invoke">
144 <MemberSignature Language="C#" Value="public virtual int Invoke (System.Collections.Generic.IEnumerable<string> arguments);" />
145 <MemberSignature Language="ILAsm" Value=".method public hidebysig newslot virtual instance int32 Invoke(class System.Collections.Generic.IEnumerable`1<string> arguments) cil managed" />
146 <MemberType>Method</MemberType>
148 <AssemblyVersion>0.2.3.0</AssemblyVersion>
151 <ReturnType>System.Int32</ReturnType>
154 <Parameter Name="arguments" Type="System.Collections.Generic.IEnumerable<System.String>" />
157 <param name="arguments">
158 A <see cref="T:System.Collections.Generic.IEnumerable{System.String}" />
159 which contains the unprocessed command-line arguments.
162 Invoked by <see cref="M:Mono.Options.CommandSet.Run" /> when a command
166 A <see cref="T:System.Int32" /> which should be treated as the process
171 The value returned by <c>Invoke()</c> is the return value of
172 <see cref="M:Mono.Options.CommandSet.Run" />, and should be treated
173 as a possible process exit value.
175 <block subset="none" type="behaviors">
177 If the <c>Invoke()</c> method is not overridden by a subclass,
178 the <c>Invoke()</c> method will use
179 <see cref="P:Mono.Options.Command.Options" /> to parse
180 <paramref name="arguments" />, and pass any un-processed values
181 on to <see cref="P:Mono.Options.Command.Run" />.
184 If the <c>Options</c> property is <see langword="null" />, then no
185 option processing will occur, and <paramref name="arguments" />
186 will be provided to the <c>Run</c> property as-is.
189 If the <c>Run</c> property is <see langword="null" />, then
190 no further processing occurs.
193 <block subset="none" type="overrides">
195 Method overrides do not need to call the base class method.
201 <Member MemberName="Name">
202 <MemberSignature Language="C#" Value="public string Name { get; }" />
203 <MemberSignature Language="ILAsm" Value=".property instance string Name" />
204 <MemberType>Property</MemberType>
206 <AssemblyVersion>0.2.3.0</AssemblyVersion>
209 <ReturnType>System.String</ReturnType>
213 The name of the <c>Command</c>, which is used for command invocation.
216 A <see cref="T:System.String" /> which is the name of the <c>Command</c>.
220 The <c>Name</c> value must be unique across all <c>Commmand</c> instances
221 referred to by a <see cref="T:Mono.Options.CommandSet" />.
226 <Member MemberName="Options">
227 <MemberSignature Language="C#" Value="public Mono.Options.OptionSet Options { get; set; }" />
228 <MemberSignature Language="ILAsm" Value=".property instance class Mono.Options.OptionSet Options" />
229 <MemberType>Property</MemberType>
231 <AssemblyVersion>0.2.3.0</AssemblyVersion>
234 <ReturnType>Mono.Options.OptionSet</ReturnType>
238 Optional command-line option information.
241 A <see cref="T:Mono.Options.OptionSet" /> instance which contains the
242 available command-line options for the <c>Command</c>.
246 If the <c>Options</c> property is not <see langword="null" /> when
247 the command is processed,
248 <see cref="M:Mono.Options.OptionSet.Parse" /> will be invoked on
249 the <c>Options</c> instance, and the return value of
250 <c>OptionSet.Parse()</c> will be forwarded to
251 <see cref="M:Mono.Options.Command.Invoke" />.
256 <Member MemberName="Run">
257 <MemberSignature Language="C#" Value="public Action<System.Collections.Generic.IEnumerable<string>> Run { get; set; }" />
258 <MemberSignature Language="ILAsm" Value=".property instance class System.Action`1<class System.Collections.Generic.IEnumerable`1<string>> Run" />
259 <MemberType>Property</MemberType>
261 <AssemblyVersion>0.2.3.0</AssemblyVersion>
264 <ReturnType>System.Action<System.Collections.Generic.IEnumerable<System.String>></ReturnType>
268 Optional command handler.
271 A <see cref="T:System.Action{System.Collections.Generic.IEnumerable{System.String}}" />
272 delegate which is executed by
273 <see cref="M:Mono.Options.Command.Invoke" />.
277 The <c>Run</c> property is executed by the the
278 <see cref="M:Mono.Options.Command.Invoke" /> method when
279 <see cref="M:Mono.Options.CommandSet.Run" /> dispatches to a
280 <c>Command</c> instance.