public object Parse(IArgumentPack pack, Type targetType) { var arg = pack.Peek().Unwrap(); if (!arg.StartsWithAny("\"", "“", "”")) { return(pack.Take()); } var allItems = new List <string>(); do { allItems.Add(pack.Take()); } while(!allItems[^ 1].EndsWithAny("\"", "“", "”"));
public static string TakeAll(this IArgumentPack pack) { List <string> allItems = new List <string>(); while (pack.CanTake) { allItems.Add(pack.Take()); } return(string.Join(" ", allItems)); }
public object Parse(IArgumentPack pack, Type targetType) { var value = pack.Take(); if (ulong.TryParse(value, out ulong result)) { return(result); } return(null); }
public virtual Node FindCommand(IArgumentPack pack) { if (!pack.CanTake) { return(null); } var arg = pack.Peek().Unwrap() .ToLowerInvariant(); // Take if this module starts. if (Metadata.Identifiers?.Any(x => x.ToLowerInvariant() == arg.ToLowerInvariant()) ?? false) { pack.Take(); } foreach (var c in Children) { if (c is NodeContainer nc) { var foundNode = nc.FindCommand(pack); if (foundNode != null) { return(foundNode); } } else { if (c.Metadata.Identifiers.Any(x => x == arg)) { pack.Take(); return(c); } } } return(null); }
public object Parse(IArgumentPack pack, Type targetType) { var item = pack.Take(); if (bool.TryParse(item, out bool valueBool)) { return(valueBool); } if (int.TryParse(item, out int valueInt)) { return(valueInt > 0); } return(null); }
/// <summary> /// Query a command recursively /// </summary> /// <param name="pack">Argument pack to iterate over.</param> /// <returns>Nullable node</returns> public override Node FindCommand(IArgumentPack pack) { var arg = pack.Peek().Unwrap() .ToLowerInvariant(); if (Metadata.Identifiers == null || !Metadata.Identifiers.Any()) { return(null); } if (Metadata.Identifiers.All(x => x != arg)) { return(null); } pack.Take(); var cmd = base.FindCommand(pack); if (cmd != null) { return(cmd); } return(this); }
/// <inheritdoc /> public object Parse(IArgumentPack pack, Type targetType) { return(Enum.Parse(targetType, pack.Take(), true)); }
public object Parse(IArgumentPack pack, Type targetType) { return(Guid.Parse(pack.Take())); }