public bool CanParse(IArgumentPack pack, Type targetType) { if (targetType != typeof(bool)) { return(false); } return(bool.TryParse(pack.Peek(), out _) || int.TryParse(pack.Peek(), out _)); }
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("\"", "“", "”"));
/// <inheritdoc/> public bool CanParse(IArgumentPack pack, Type targetType) { if (targetType != typeof(int)) { return(false); } var value = pack.Peek(); if (!value.HasValue) { return(false); } var argument = value.Unwrap(); return(suffixes.ContainsKey(char.ToLowerInvariant(argument.Last())) && int.TryParse(argument[..^ 1], out _));
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); }
/// <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 bool CanParse(IArgumentPack pack, Type targetType) { return(Enum.TryParse(targetType, pack.Peek(), true, out _)); }