NTP Analyzer  0.8.2
Analyze the operation of time servers
Ntp.Common.IO.OptionSet Class Reference
Inheritance diagram for Ntp.Common.IO.OptionSet:
Collaboration diagram for Ntp.Common.IO.OptionSet:

Classes

class  ActionOption
 
class  ActionOption
 
class  ActionOption
 
class  ArgumentEnumerator
 
class  Category
 

Public Member Functions

 OptionSet ()
 
 OptionSet (MessageLocalizerConverter localizer)
 
OptionSet Add (string header)
 
new OptionSet Add (Option option)
 
OptionSet Add (string prototype, Action< string > action)
 
OptionSet Add (string prototype, string description, Action< string > action)
 
OptionSet Add (string prototype, string description, Action< string > action, bool hidden)
 
OptionSet Add (string prototype, OptionAction< string, string > action)
 
OptionSet Add (string prototype, string description, OptionAction< string, string > action)
 
OptionSet Add (string prototype, string description, OptionAction< string, string > action, bool hidden)
 
OptionSet Add (ArgumentSource source)
 
OptionSet Add< T > (string prototype, Action< T > action)
 
OptionSet Add< T > (string prototype, string description, Action< T > action)
 
OptionSet Add< TKey, TValue > (string prototype, OptionAction< TKey, TValue > action)
 
OptionSet Add< TKey, TValue > (string prototype, string description, OptionAction< TKey, TValue > action)
 
List< string > Parse (IEnumerable< string > arguments)
 
void WriteOptionDescriptions (TextWriter o)
 

Protected Member Functions

virtual OptionContext CreateOptionContext ()
 
override string GetKeyForItem (Option item)
 
Option GetOptionForName (string option)
 
bool GetOptionParts (string argument, out string flag, out string name, out string sep, out string value)
 
override void InsertItem (int index, Option item)
 
virtual bool Parse (string argument, OptionContext c)
 
override void RemoveItem (int index)
 
override void SetItem (int index, Option item)
 

Properties

ReadOnlyCollection< ArgumentSourceArgumentSources [get]
 
MessageLocalizerConverter MessageLocalizer [get]
 

Private Member Functions

void AddImpl (Option option)
 
bool AddSource (ArgumentEnumerator ae, string argument)
 
bool ParseBool (string option, string n, OptionContext c)
 
bool ParseBundledValue (string f, string n, OptionContext c)
 
void ParseValue (string option, OptionContext c)
 
void WriteDescription (TextWriter o, string value, string prefix, int firstWidth, int remWidth)
 
bool WriteOptionPrototype (TextWriter o, Option p, ref int written)
 

Static Private Member Functions

static string GetArgumentName (int index, int maxIndex, string description)
 
static string GetDescription (string description)
 
static IEnumerable< string > GetLines (string description, int firstWidth, int remWidth)
 
static int GetNextOptionIndex (string[] names, int i)
 
static void Invoke (OptionContext c, string name, string value, Option option)
 
static void Unprocessed (ICollection< string > extra, Option def, OptionContext c, string argument)
 
static void Write (TextWriter o, ref int n, string s)
 

Private Attributes

const int DescriptionFirstWidth = 80 - OptionWidth
 
const int DescriptionRemWidth = 80 - OptionWidth - 2
 
const int OptionWidth = 29
 
readonly List< ArgumentSourcesources = new List<ArgumentSource>()
 
readonly Regex valueOption
 

Detailed Description

Definition at line 785 of file Options.cs.

Constructor & Destructor Documentation

Ntp.Common.IO.OptionSet.OptionSet ( )
inline

Definition at line 787 of file Options.cs.

788  : this(f => f)
789  {
790  }
Ntp.Common.IO.OptionSet.OptionSet ( MessageLocalizerConverter  localizer)
inline

Definition at line 792 of file Options.cs.

793  {
794  MessageLocalizer = localizer;
795  ArgumentSources = new ReadOnlyCollection<ArgumentSource>(sources);
796  }
ReadOnlyCollection< ArgumentSource > ArgumentSources
Definition: Options.cs:809
readonly List< ArgumentSource > sources
Definition: Options.cs:802
MessageLocalizerConverter MessageLocalizer
Definition: Options.cs:807

Member Function Documentation

OptionSet Ntp.Common.IO.OptionSet.Add ( string  header)
inline

Definition at line 811 of file Options.cs.

Referenced by Ntp.Common.IO.OptionSet.Add().

812  {
813  if (header == null)
814  throw new ArgumentNullException(nameof(header));
815  Add(new Category(header));
816  return this;
817  }
OptionSet Add(string header)
Definition: Options.cs:811

Here is the caller graph for this function:

new OptionSet Ntp.Common.IO.OptionSet.Add ( Option  option)
inline

Definition at line 820 of file Options.cs.

References Ntp.Common.IO.OptionSet.Add().

821  {
822  base.Add(option);
823  return this;
824  }

Here is the call graph for this function:

OptionSet Ntp.Common.IO.OptionSet.Add ( string  prototype,
Action< string >  action 
)
inline

Definition at line 826 of file Options.cs.

827  {
828  return Add(prototype, null, action);
829  }
OptionSet Add(string header)
Definition: Options.cs:811
OptionSet Ntp.Common.IO.OptionSet.Add ( string  prototype,
string  description,
Action< string >  action 
)
inline

Definition at line 831 of file Options.cs.

832  {
833  return Add(prototype, description, action, false);
834  }
OptionSet Add(string header)
Definition: Options.cs:811
OptionSet Ntp.Common.IO.OptionSet.Add ( string  prototype,
string  description,
Action< string >  action,
bool  hidden 
)
inline

Definition at line 836 of file Options.cs.

837  {
838  if (action == null)
839  throw new ArgumentNullException(nameof(action));
840  Option p = new ActionOption(prototype, description, 1,
841  delegate(OptionValueCollection v) { action(v[0]); }, hidden);
842  base.Add(p);
843  return this;
844  }
OptionSet Ntp.Common.IO.OptionSet.Add ( string  prototype,
OptionAction< string, string >  action 
)
inline

Definition at line 846 of file Options.cs.

847  {
848  return Add(prototype, null, action);
849  }
OptionSet Add(string header)
Definition: Options.cs:811
OptionSet Ntp.Common.IO.OptionSet.Add ( string  prototype,
string  description,
OptionAction< string, string >  action 
)
inline

Definition at line 851 of file Options.cs.

852  {
853  return Add(prototype, description, action, false);
854  }
OptionSet Add(string header)
Definition: Options.cs:811
OptionSet Ntp.Common.IO.OptionSet.Add ( string  prototype,
string  description,
OptionAction< string, string >  action,
bool  hidden 
)
inline

Definition at line 856 of file Options.cs.

857  {
858  if (action == null)
859  throw new ArgumentNullException(nameof(action));
860  Option p = new ActionOption(prototype, description, 2,
861  delegate(OptionValueCollection v) { action(v[0], v[1]); }, hidden);
862  base.Add(p);
863  return this;
864  }
OptionSet Ntp.Common.IO.OptionSet.Add ( ArgumentSource  source)
inline

Definition at line 886 of file Options.cs.

887  {
888  if (source == null)
889  throw new ArgumentNullException(nameof(source));
890  sources.Add(source);
891  return this;
892  }
readonly List< ArgumentSource > sources
Definition: Options.cs:802
OptionSet Ntp.Common.IO.OptionSet.Add< T > ( string  prototype,
Action< T >  action 
)
inline

Definition at line 866 of file Options.cs.

867  {
868  return Add(prototype, null, action);
869  }
OptionSet Add(string header)
Definition: Options.cs:811
OptionSet Ntp.Common.IO.OptionSet.Add< T > ( string  prototype,
string  description,
Action< T >  action 
)
inline

Definition at line 871 of file Options.cs.

872  {
873  return Add(new ActionOption<T>(prototype, description, action));
874  }
OptionSet Add(string header)
Definition: Options.cs:811
OptionSet Ntp.Common.IO.OptionSet.Add< TKey, TValue > ( string  prototype,
OptionAction< TKey, TValue >  action 
)
inline

Definition at line 876 of file Options.cs.

877  {
878  return Add(prototype, null, action);
879  }
OptionSet Add(string header)
Definition: Options.cs:811
OptionSet Ntp.Common.IO.OptionSet.Add< TKey, TValue > ( string  prototype,
string  description,
OptionAction< TKey, TValue >  action 
)
inline

Definition at line 881 of file Options.cs.

882  {
883  return Add(new ActionOption<TKey, TValue>(prototype, description, action));
884  }
OptionSet Add(string header)
Definition: Options.cs:811
void Ntp.Common.IO.OptionSet.AddImpl ( Option  option)
inlineprivate

Definition at line 1101 of file Options.cs.

References Ntp.Common.IO.Option.Names.

1102  {
1103  if (option == null)
1104  throw new ArgumentNullException(nameof(option));
1105  var added = new List<string>(option.Names.Length);
1106  try
1107  {
1108  // KeyedCollection.InsertItem/SetItem handle the 0th name.
1109  for (var i = 1; i < option.Names.Length; ++i)
1110  {
1111  Dictionary.Add(option.Names[i], option);
1112  added.Add(option.Names[i]);
1113  }
1114  }
1115  catch (Exception)
1116  {
1117  foreach (var name in added)
1118  Dictionary.Remove(name);
1119  throw;
1120  }
1121  }
bool Ntp.Common.IO.OptionSet.AddSource ( ArgumentEnumerator  ae,
string  argument 
)
inlineprivate

Definition at line 1123 of file Options.cs.

1124  {
1125  foreach (var source in sources)
1126  {
1127  IEnumerable<string> replacement;
1128  if (!source.GetArguments(argument, out replacement))
1129  continue;
1130  ae.Add(replacement);
1131  return true;
1132  }
1133  return false;
1134  }
readonly List< ArgumentSource > sources
Definition: Options.cs:802
virtual OptionContext Ntp.Common.IO.OptionSet.CreateOptionContext ( )
inlineprotectedvirtual

Definition at line 989 of file Options.cs.

990  {
991  return new OptionContext(this);
992  }
static string Ntp.Common.IO.OptionSet.GetArgumentName ( int  index,
int  maxIndex,
string  description 
)
inlinestaticprivate

Definition at line 1136 of file Options.cs.

1137  {
1138  if (description == null)
1139  return maxIndex == 1 ? "VALUE" : "VALUE" + (index + 1);
1140 
1141  var nameStart = maxIndex == 1 ? new[] {"{0:", "{"} : new[] {"{" + index + ":"};
1142 
1143  foreach (var t in nameStart)
1144  {
1145  int start, j = 0;
1146  do
1147  {
1148  start = description.IndexOf(t, j, StringComparison.Ordinal);
1149  } while (start >= 0 && j != 0 && description[j++ - 1] == '{');
1150  if (start == -1)
1151  continue;
1152  var end = description.IndexOf("}", start, StringComparison.Ordinal);
1153  if (end == -1)
1154  continue;
1155  return description.Substring(start + t.Length, end - start - t.Length);
1156  }
1157 
1158  return maxIndex == 1 ? "VALUE" : "VALUE" + (index + 1);
1159  }
static string Ntp.Common.IO.OptionSet.GetDescription ( string  description)
inlinestaticprivate

Definition at line 1161 of file Options.cs.

1162  {
1163  if (description == null)
1164  return string.Empty;
1165  var sb = new StringBuilder(description.Length);
1166  var start = -1;
1167  for (var i = 0; i < description.Length; ++i)
1168  {
1169  switch (description[i])
1170  {
1171  case '{':
1172  if (i == start)
1173  {
1174  sb.Append('{');
1175  start = -1;
1176  }
1177  else if (start < 0)
1178  start = i + 1;
1179  break;
1180  case '}':
1181  if (start < 0)
1182  {
1183  if (i + 1 == description.Length || description[i + 1] != '}')
1184  throw new InvalidOperationException("Invalid option description: " + description);
1185  ++i;
1186  sb.Append("}");
1187  }
1188  else
1189  {
1190  sb.Append(description.Substring(start, i - start));
1191  start = -1;
1192  }
1193  break;
1194  case ':':
1195  if (start < 0)
1196  goto default;
1197  start = i + 1;
1198  break;
1199  default:
1200  if (start < 0)
1201  sb.Append(description[i]);
1202  break;
1203  }
1204  }
1205  return sb.ToString();
1206  }
override string Ntp.Common.IO.OptionSet.GetKeyForItem ( Option  item)
inlineprotected

Definition at line 995 of file Options.cs.

References Ntp.Common.IO.Option.Names.

996  {
997  if (item == null)
998  throw new ArgumentNullException(nameof(item));
999  if (item.Names != null && item.Names.Length > 0)
1000  return item.Names[0];
1001  // This should never happen, as it's invalid for Option to be
1002  // constructed w/o any names.
1003  throw new InvalidOperationException("Option has no names!");
1004  }
static IEnumerable<string> Ntp.Common.IO.OptionSet.GetLines ( string  description,
int  firstWidth,
int  remWidth 
)
inlinestaticprivate

Definition at line 1208 of file Options.cs.

References Ntp.Common.IO.StringCoda.WrappedLines().

1209  {
1210  return StringCoda.WrappedLines(description, firstWidth, remWidth);
1211  }

Here is the call graph for this function:

static int Ntp.Common.IO.OptionSet.GetNextOptionIndex ( string[]  names,
int  i 
)
inlinestaticprivate

Definition at line 1213 of file Options.cs.

1214  {
1215  while (i < names.Length && names[i] == "<>")
1216  {
1217  ++i;
1218  }
1219  return i;
1220  }
Option Ntp.Common.IO.OptionSet.GetOptionForName ( string  option)
inlineprotected

Definition at line 1007 of file Options.cs.

1008  {
1009  if (option == null)
1010  throw new ArgumentNullException(nameof(option));
1011  try
1012  {
1013  return base[option];
1014  }
1015  catch (KeyNotFoundException)
1016  {
1017  return null;
1018  }
1019  }
bool Ntp.Common.IO.OptionSet.GetOptionParts ( string  argument,
out string  flag,
out string  name,
out string  sep,
out string  value 
)
inlineprotected

Definition at line 1021 of file Options.cs.

1023  {
1024  if (argument == null)
1025  throw new ArgumentNullException(nameof(argument));
1026 
1027  flag = name = sep = value = null;
1028  var m = valueOption.Match(argument);
1029  if (!m.Success)
1030  {
1031  return false;
1032  }
1033  flag = m.Groups["flag"].Value;
1034  name = m.Groups["name"].Value;
1035  if (m.Groups["sep"].Success && m.Groups["value"].Success)
1036  {
1037  sep = m.Groups["sep"].Value;
1038  value = m.Groups["value"].Value;
1039  }
1040  return true;
1041  }
readonly Regex valueOption
Definition: Options.cs:804
override void Ntp.Common.IO.OptionSet.InsertItem ( int  index,
Option  item 
)
inlineprotected

Definition at line 1043 of file Options.cs.

1044  {
1045  base.InsertItem(index, item);
1046  AddImpl(item);
1047  }
void AddImpl(Option option)
Definition: Options.cs:1101
static void Ntp.Common.IO.OptionSet.Invoke ( OptionContext  c,
string  name,
string  value,
Option  option 
)
inlinestaticprivate

Definition at line 1222 of file Options.cs.

References Ntp.Common.IO.OptionValueCollection.Add(), Ntp.Common.IO.Option.Invoke(), Ntp.Common.IO.OptionContext.Option, Ntp.Common.IO.OptionContext.OptionName, and Ntp.Common.IO.OptionContext.OptionValues.

1223  {
1224  c.OptionName = name;
1225  c.Option = option;
1226  c.OptionValues.Add(value);
1227  option.Invoke(c);
1228  }
var c
Definition: bootstrap.min.js:6

Here is the call graph for this function:

List<string> Ntp.Common.IO.OptionSet.Parse ( IEnumerable< string >  arguments)
inline

Definition at line 894 of file Options.cs.

895  {
896  if (arguments == null)
897  throw new ArgumentNullException(nameof(arguments));
898 
899  var c = CreateOptionContext();
900  c.OptionIndex = -1;
901  var process = true;
902  var unprocessed = new List<string>();
903  var def = Contains("<>") ? this["<>"] : null;
904  var ae = new ArgumentEnumerator(arguments);
905 
906  foreach (var argument in ae)
907  {
908  ++c.OptionIndex;
909  if (argument == "--")
910  {
911  process = false;
912  continue;
913  }
914  if (!process)
915  {
916  Unprocessed(unprocessed, def, c, argument);
917  continue;
918  }
919  if (AddSource(ae, argument))
920  continue;
921  if (!Parse(argument, c))
922  Unprocessed(unprocessed, def, c, argument);
923  }
924 
925  c.Option?.Invoke(c);
926  return unprocessed;
927  }
static void Unprocessed(ICollection< string > extra, Option def, OptionContext c, string argument)
Definition: Options.cs:1305
virtual OptionContext CreateOptionContext()
Definition: Options.cs:989
var c
Definition: bootstrap.min.js:6
bool AddSource(ArgumentEnumerator ae, string argument)
Definition: Options.cs:1123
List< string > Parse(IEnumerable< string > arguments)
Definition: Options.cs:894
virtual bool Ntp.Common.IO.OptionSet.Parse ( string  argument,
OptionContext  c 
)
inlineprotectedvirtual

Definition at line 1049 of file Options.cs.

References Ntp.Common.IO.OptionValueCollection.Add(), Ntp.Common.IO.Option.Invoke(), Ntp.Common.IO.OptionContext.Option, Ntp.Common.IO.OptionContext.OptionName, Ntp.Common.IO.OptionContext.OptionValues, and s().

1050  {
1051  if (c.Option != null)
1052  {
1053  ParseValue(argument, c);
1054  return true;
1055  }
1056 
1057  string f, n, s, v;
1058  if (!GetOptionParts(argument, out f, out n, out s, out v))
1059  return false;
1060 
1061  if (Contains(n))
1062  {
1063  var p = this[n];
1064  c.OptionName = f + n;
1065  c.Option = p;
1066  switch (p.OptionValueType)
1067  {
1068  case OptionValueType.None:
1069  c.OptionValues.Add(n);
1070  c.Option.Invoke(c);
1071  break;
1072  case OptionValueType.Optional:
1073  case OptionValueType.Required:
1074  ParseValue(v, c);
1075  break;
1076  }
1077  return true;
1078  }
1079 
1080  // no match; is it a bool option?
1081  return ParseBool(argument, n, c) || ParseBundledValue(f, $"{n}{s}{v}", c);
1082  }
bool ParseBool(string option, string n, OptionContext c)
Definition: Options.cs:1230
bool GetOptionParts(string argument, out string flag, out string name, out string sep, out string value)
Definition: Options.cs:1021
var c
Definition: bootstrap.min.js:6
bool ParseBundledValue(string f, string n, OptionContext c)
Definition: Options.cs:1247
function s(a)
Definition: jquery.min.js:2
void ParseValue(string option, OptionContext c)
Definition: Options.cs:1284

Here is the call graph for this function:

bool Ntp.Common.IO.OptionSet.ParseBool ( string  option,
string  n,
OptionContext  c 
)
inlineprivate

Definition at line 1230 of file Options.cs.

References Ntp.Common.IO.OptionValueCollection.Add(), Ntp.Common.IO.OptionContext.Option, Ntp.Common.IO.OptionContext.OptionName, and Ntp.Common.IO.OptionContext.OptionValues.

1231  {
1232  string rn;
1233  if (n.Length >= 1 && (n[n.Length - 1] == '+' || n[n.Length - 1] == '-') &&
1234  Contains(rn = n.Substring(0, n.Length - 1)))
1235  {
1236  var p = this[rn];
1237  var v = n[n.Length - 1] == '+' ? option : null;
1238  c.OptionName = option;
1239  c.Option = p;
1240  c.OptionValues.Add(v);
1241  p.Invoke(c);
1242  return true;
1243  }
1244  return false;
1245  }
var c
Definition: bootstrap.min.js:6

Here is the call graph for this function:

bool Ntp.Common.IO.OptionSet.ParseBundledValue ( string  f,
string  n,
OptionContext  c 
)
inlineprivate

Definition at line 1247 of file Options.cs.

References Ntp.Common.IO.OptionContext.Option, and Ntp.Common.IO.OptionContext.OptionName.

1248  {
1249  if (f != "-")
1250  return false;
1251  for (var i = 0; i < n.Length; ++i)
1252  {
1253  var opt = f + n[i];
1254  var rn = n[i].ToString();
1255  if (!Contains(rn))
1256  {
1257  if (i == 0)
1258  return false;
1259  throw new OptionException(string.Format(MessageLocalizer(
1260  "Cannot use unregistered option '{0}' in bundle '{1}'."), rn, f + n), null);
1261  }
1262  var p = this[rn];
1263  switch (p.OptionValueType)
1264  {
1265  case OptionValueType.None:
1266  Invoke(c, opt, n, p);
1267  break;
1268  case OptionValueType.Optional:
1269  case OptionValueType.Required:
1270  {
1271  var v = n.Substring(i + 1);
1272  c.Option = p;
1273  c.OptionName = opt;
1274  ParseValue(v.Length != 0 ? v : null, c);
1275  return true;
1276  }
1277  default:
1278  throw new InvalidOperationException("Unknown OptionValueType: " + p.OptionValueType);
1279  }
1280  }
1281  return true;
1282  }
static void Invoke(OptionContext c, string name, string value, Option option)
Definition: Options.cs:1222
var c
Definition: bootstrap.min.js:6
MessageLocalizerConverter MessageLocalizer
Definition: Options.cs:807
void ParseValue(string option, OptionContext c)
Definition: Options.cs:1284
void Ntp.Common.IO.OptionSet.ParseValue ( string  option,
OptionContext  c 
)
inlineprivate

Definition at line 1284 of file Options.cs.

1285  {
1286  if (option != null)
1287  foreach (var o in c.Option.ValueSeparators != null
1288  ? option.Split(c.Option.ValueSeparators, c.Option.MaxValueCount - c.OptionValues.Count,
1289  StringSplitOptions.None)
1290  : new[] {option})
1291  {
1292  c.OptionValues.Add(o);
1293  }
1294  if (c.OptionValues.Count == c.Option.MaxValueCount ||
1295  c.Option.OptionValueType == OptionValueType.Optional)
1296  c.Option.Invoke(c);
1297  else if (c.OptionValues.Count > c.Option.MaxValueCount)
1298  {
1299  throw new OptionException(MessageLocalizer(
1300  $"Error: Found {c.OptionValues.Count} option values when expecting {c.Option.MaxValueCount}."),
1301  c.OptionName);
1302  }
1303  }
var c
Definition: bootstrap.min.js:6
MessageLocalizerConverter MessageLocalizer
Definition: Options.cs:807
override void Ntp.Common.IO.OptionSet.RemoveItem ( int  index)
inlineprotected

Definition at line 1084 of file Options.cs.

1085  {
1086  var p = Items[index];
1087  base.RemoveItem(index);
1088  // KeyedCollection.RemoveItem() handles the 0th item
1089  for (var i = 1; i < p.Names.Length; ++i)
1090  {
1091  Dictionary.Remove(p.Names[i]);
1092  }
1093  }
override void Ntp.Common.IO.OptionSet.SetItem ( int  index,
Option  item 
)
inlineprotected

Definition at line 1095 of file Options.cs.

1096  {
1097  base.SetItem(index, item);
1098  AddImpl(item);
1099  }
void AddImpl(Option option)
Definition: Options.cs:1101
static void Ntp.Common.IO.OptionSet.Unprocessed ( ICollection< string >  extra,
Option  def,
OptionContext  c,
string  argument 
)
inlinestaticprivate

Definition at line 1305 of file Options.cs.

References Ntp.Common.IO.OptionValueCollection.Add(), Ntp.Common.IO.Option.Invoke(), Ntp.Common.IO.OptionContext.Option, and Ntp.Common.IO.OptionContext.OptionValues.

1306  {
1307  if (def == null)
1308  {
1309  extra.Add(argument);
1310  return;
1311  }
1312  c.OptionValues.Add(argument);
1313  c.Option = def;
1314  c.Option.Invoke(c);
1315  }
var c
Definition: bootstrap.min.js:6

Here is the call graph for this function:

static void Ntp.Common.IO.OptionSet.Write ( TextWriter  o,
ref int  n,
string  s 
)
inlinestaticprivate

Definition at line 1317 of file Options.cs.

1318  {
1319  n += s.Length;
1320  o.Write(s);
1321  }
function s(a)
Definition: jquery.min.js:2
void Ntp.Common.IO.OptionSet.WriteDescription ( TextWriter  o,
string  value,
string  prefix,
int  firstWidth,
int  remWidth 
)
inlineprivate

Definition at line 1323 of file Options.cs.

1324  {
1325  var indent = false;
1326  foreach (var line in GetLines(MessageLocalizer(GetDescription(value)), firstWidth, remWidth))
1327  {
1328  if (indent)
1329  o.Write(prefix);
1330  o.WriteLine(line);
1331  indent = true;
1332  }
1333  }
static string GetDescription(string description)
Definition: Options.cs:1161
static IEnumerable< string > GetLines(string description, int firstWidth, int remWidth)
Definition: Options.cs:1208
MessageLocalizerConverter MessageLocalizer
Definition: Options.cs:807
void Ntp.Common.IO.OptionSet.WriteOptionDescriptions ( TextWriter  o)
inline

Definition at line 929 of file Options.cs.

References s().

930  {
931  foreach (var p in this)
932  {
933  var written = 0;
934 
935  if (p.Hidden)
936  continue;
937 
938  var c = p as Category;
939  if (c != null)
940  {
941  WriteDescription(o, p.Description, "", 80, 80);
942  continue;
943  }
944 
945  if (!WriteOptionPrototype(o, p, ref written))
946  continue;
947 
948  if (written < OptionWidth)
949  o.Write(new string(' ', OptionWidth - written));
950  else
951  {
952  o.WriteLine();
953  o.Write(new string(' ', OptionWidth));
954  }
955 
956  WriteDescription(o, p.Description, new string(' ', OptionWidth + 2),
958  }
959 
960  foreach (var s in sources)
961  {
962  var names = s.GetNames();
963  if (names == null || names.Length == 0)
964  continue;
965 
966  var written = 0;
967 
968  Write(o, ref written, " ");
969  Write(o, ref written, names[0]);
970  for (var i = 1; i < names.Length; ++i)
971  {
972  Write(o, ref written, ", ");
973  Write(o, ref written, names[i]);
974  }
975 
976  if (written < OptionWidth)
977  o.Write(new string(' ', OptionWidth - written));
978  else
979  {
980  o.WriteLine();
981  o.Write(new string(' ', OptionWidth));
982  }
983 
984  WriteDescription(o, s.Description, new string(' ', OptionWidth + 2),
986  }
987  }
const int DescriptionRemWidth
Definition: Options.cs:800
bool WriteOptionPrototype(TextWriter o, Option p, ref int written)
Definition: Options.cs:1335
const int OptionWidth
Definition: Options.cs:798
var c
Definition: bootstrap.min.js:6
static void Write(TextWriter o, ref int n, string s)
Definition: Options.cs:1317
void WriteDescription(TextWriter o, string value, string prefix, int firstWidth, int remWidth)
Definition: Options.cs:1323
const int DescriptionFirstWidth
Definition: Options.cs:799
readonly List< ArgumentSource > sources
Definition: Options.cs:802
function s(a)
Definition: jquery.min.js:2

Here is the call graph for this function:

bool Ntp.Common.IO.OptionSet.WriteOptionPrototype ( TextWriter  o,
Option  p,
ref int  written 
)
inlineprivate

Definition at line 1335 of file Options.cs.

References c, Ntp.Common.IO.Option.Description, Ntp.Common.IO.Option.MaxValueCount, Ntp.Common.IO.Option.Names, Ntp.Common.IO.Option.OptionValueType, and Ntp.Common.IO.Option.ValueSeparators.

1336  {
1337  var names = p.Names;
1338 
1339  var i = GetNextOptionIndex(names, 0);
1340  if (i == names.Length)
1341  return false;
1342 
1343  if (names[i].Length == 1)
1344  {
1345  Write(o, ref written, " -");
1346  Write(o, ref written, names[0]);
1347  }
1348  else
1349  {
1350  Write(o, ref written, " --");
1351  Write(o, ref written, names[0]);
1352  }
1353 
1354  for (i = GetNextOptionIndex(names, i + 1);
1355  i < names.Length;
1356  i = GetNextOptionIndex(names, i + 1))
1357  {
1358  Write(o, ref written, ", ");
1359  Write(o, ref written, names[i].Length == 1 ? "-" : "--");
1360  Write(o, ref written, names[i]);
1361  }
1362 
1363  if (p.OptionValueType == OptionValueType.Optional ||
1364  p.OptionValueType == OptionValueType.Required)
1365  {
1366  if (p.OptionValueType == OptionValueType.Optional)
1367  {
1368  Write(o, ref written, MessageLocalizer("["));
1369  }
1370  Write(o, ref written, MessageLocalizer("=" + GetArgumentName(0, p.MaxValueCount, p.Description)));
1371  var sep = p.ValueSeparators != null && p.ValueSeparators.Length > 0
1372  ? p.ValueSeparators[0]
1373  : " ";
1374  for (var c = 1; c < p.MaxValueCount; ++c)
1375  {
1376  Write(o, ref written, MessageLocalizer(sep + GetArgumentName(c, p.MaxValueCount, p.Description)));
1377  }
1378  if (p.OptionValueType == OptionValueType.Optional)
1379  {
1380  Write(o, ref written, MessageLocalizer("]"));
1381  }
1382  }
1383  return true;
1384  }
static int GetNextOptionIndex(string[] names, int i)
Definition: Options.cs:1213
static string GetArgumentName(int index, int maxIndex, string description)
Definition: Options.cs:1136
var c
Definition: bootstrap.min.js:6
static void Write(TextWriter o, ref int n, string s)
Definition: Options.cs:1317
MessageLocalizerConverter MessageLocalizer
Definition: Options.cs:807

Member Data Documentation

const int Ntp.Common.IO.OptionSet.DescriptionFirstWidth = 80 - OptionWidth
private

Definition at line 799 of file Options.cs.

const int Ntp.Common.IO.OptionSet.DescriptionRemWidth = 80 - OptionWidth - 2
private

Definition at line 800 of file Options.cs.

const int Ntp.Common.IO.OptionSet.OptionWidth = 29
private

Definition at line 798 of file Options.cs.

readonly List<ArgumentSource> Ntp.Common.IO.OptionSet.sources = new List<ArgumentSource>()
private

Definition at line 802 of file Options.cs.

readonly Regex Ntp.Common.IO.OptionSet.valueOption
private
Initial value:
= new Regex(
@"^(?<flag>--|-|/)(?<name>[^:=]+)((?<sep>[:=])(?<value>.*))?$")

Definition at line 804 of file Options.cs.

Property Documentation

ReadOnlyCollection<ArgumentSource> Ntp.Common.IO.OptionSet.ArgumentSources
get

Definition at line 809 of file Options.cs.

MessageLocalizerConverter Ntp.Common.IO.OptionSet.MessageLocalizer
get

Definition at line 807 of file Options.cs.

Referenced by Ntp.Common.IO.Option.Parse< T >().


The documentation for this class was generated from the following file: