4using System.Collections.Generic;
21 public static Func<SentenceBuilder>
Factory {
get;
set; } = () =>
new DefaultSentenceBuilder();
84#region Nested type: DefaultSentenceBuilder
90 get {
return () =>
"Required."; }
95 get {
return () =>
"ERROR(S):"; }
100 get {
return () =>
"USAGE:"; }
105 get {
return () =>
"Group"; }
112 return isOption => isOption
113 ?
"Display this help screen."
114 :
"Display more information on a specific command.";
120 get {
return _ =>
"Display version information."; }
139 case ErrorType.MissingRequiredOptionError:
143 ?
"A required value not bound to option name is missing."
144 :
"Required option '".JoinTo(errMisssing.
NameInfo.
NameText,
"' is missing.");
149 ?
"A value not bound to option name is defined with a bad format."
151 "' is defined with a bad format."
157 ?
"A sequence value not bound to option name is defined with fewer items than required."
159 "' is defined with fewer or more items than required."
164 return "No verb selected.";
167 "' is defined multiple times."
172 return "Error setting value to option '".JoinTo(setValueError.
NameInfo.
NameText,
179 return "At least one option from group '".JoinTo(missingGroupOptionError.
Group,
181 string.Join(
", ", missingGroupOptionError.
Names.Select(n => n.NameText)),
184 case ErrorType.GroupOptionAmbiguityError:
187 return "Both SetName and Group are not allowed in option: ("
189 case ErrorType.MultipleDefaultVerbsError:
193 throw new InvalidOperationException();
204 var bySet = from e in errors
207 select
new { SetName = g.Key, Errors = g.ToList() };
209 string[] msgs = bySet.Select(
set =>
211 string names =
string.Join(
string.Empty,
212 (from e in
set.Errors
213 select
"'".JoinTo(e.NameInfo.NameText,
217 int namesCount =
set.Errors.Count();
219 string incompat =
string.Join(
string.Empty,
232 select
"'".JoinTo(x.NameInfo
239 new StringBuilder(
"Option")
240 .AppendWhen(namesCount > 1,
"s")
242 .Append(names.Substring(0, names.Length - 2))
244 .AppendIf(namesCount > 1,
"are",
"is")
245 .Append(
" not compatible with: ")
246 .Append(incompat.Substring(0, incompat.Length - 2))
253 return string.Join(Environment.NewLine, msgs);
Models an error generated when an unknown verb is detected.
IEnumerable< NameInfo > Names
Models an error generated when a required option is required.
Models an error generated when an option lacks its value.
Models an error generated when multiple default verbs are defined.
const string ErrorMessage
Models name information, used in CommandLine.Error instances.
string NameText
Gets a formatted text with unified name information.
static readonly NameInfo EmptyName
Represents an empty name information. Used when CommandLine.Error are tied to values,...
bool Equals(NameInfo other)
Returns a value that indicates whether the current instance and a specified CommandLine....
NameInfo NameInfo
Name information relative to this error instance.
Models an error generated when an option is repeated two or more times.
Models an error generated when a sequence value lacks elements.
Models as error generated when exception is thrown at Property.SetValue.
Exception Exception
The expection thrown from Property.SetValue.
override Func< string > UsageHeadingText
override Func< bool, string > VersionCommandText
override Func< string > OptionGroupWord
override Func< IEnumerable< MutuallyExclusiveSetError >, string > FormatMutuallyExclusiveSetErrors
override Func< Error, string > FormatError
override Func< string > ErrorsHeadingText
override Func< bool, string > HelpCommandText
override Func< string > RequiredWord
Exposes standard delegates to provide a mean to customize part of help screen generation....
static SentenceBuilder Create()
Create instance of CommandLine.Text.SentenceBuilder,.
Func< string > RequiredWord
Gets a delegate that returns the word 'required'.
Func< string > UsageHeadingText
Gets a delegate that returns usage text block heading text.
Func< IEnumerable< MutuallyExclusiveSetError >, string > FormatMutuallyExclusiveSetErrors
Gets a delegate that handles mutually exclusive set errors formatting. The delegates must accept a se...
Func< string > ErrorsHeadingText
Gets a delegate that returns that errors block heading text.
Func< string > OptionGroupWord
Gets a delegate that returns the word 'group'.
static Func< SentenceBuilder > Factory
Factory to allow custom SentenceBuilder injection.
Func< bool, string > HelpCommandText
Get a delegate that returns the help text of help command. The delegates must accept a boolean that i...
Func< Error, string > FormatError
Gets a delegate that handles singular error formatting. The delegates must accept an Error and return...
Func< bool, string > VersionCommandText
Get a delegate that returns the help text of vesion command. The delegates must accept a boolean that...
Models an error generated when an unknown option is detected.
ErrorType
Discriminator enumeration of CommandLine.Error derivates.