public void AddChild(CommandNode <TSource> node)
        {
            if (node is RootCommandNode <TSource> )
            {
                throw new InvalidOperationException($"Cannot add a {nameof(RootCommandNode<TSource>)} as a child to any other {nameof(CommandNode<TSource>)}");
            }

            if (_children.TryGetValue(node.Name, out var child))
            {
                // We've found something to merge onto
                if (node.Command != null)
                {
                    child.Command = node.Command;
                }

                foreach (var grandchild in node.Children)
                {
                    child.AddChild(grandchild);
                }
            }
            else
            {
                _children.Add(node.Name, node);
                if (node is LiteralCommandNode <TSource> literalCommandNode)
                {
                    _literals.Add(node.Name, literalCommandNode);
                }
                else if (node is ArgumentCommandNode <TSource> argumentCommandNode)
                {
                    _arguments.Add(node.Name, argumentCommandNode);
                }
            }
        }
Beispiel #2
0
 protected CommandNode(Command <TSource> command, Predicate <TSource> requirement, CommandNode <TSource> redirect, RedirectModifier <TSource> modifier, bool forks)
 {
     Command          = command;
     Requirement      = requirement;
     Redirect         = redirect;
     RedirectModifier = modifier;
     IsFork           = forks;
 }
 public bool Equals(CommandNode <TSource> other)
 {
     if (other is null)
     {
         return(false);
     }
     return(ReferenceEquals(this, other) || EqualsInternal(other));
 }
Beispiel #4
0
        public int CompareTo(CommandNode <TSource> o)
        {
            if (this is LiteralCommandNode <TSource> == o is LiteralCommandNode <TSource> )
            {
                return(string.Compare(SortedKey, o.SortedKey, StringComparison.Ordinal));
            }

            return((o is LiteralCommandNode <TSource>) ? 1 : -1);
        }
Beispiel #5
0
 protected CommandNode(Command <TSource> command, Predicate <TSource> requirement, CommandNode <TSource> redirect, RedirectModifier <TSource> modifier, bool forks, string desc = "")
 {
     Command          = command;
     Requirement      = requirement;
     Redirect         = redirect;
     RedirectModifier = modifier;
     IsFork           = forks;
     Description      = desc;
 }
Beispiel #6
0
        public void AddChild(CommandNode <TSource> node)
        {
            if (node is RootCommandNode <TSource> )
            {
                throw new InvalidOperationException($"Cannot add a {nameof(RootCommandNode<TSource>)} as a child to any other {nameof(CommandNode<TSource>)}");
            }

            if (_children.TryGetValue(node.Name, out var child))
            {
                // We've found something to merge onto
                if (node.Command != null)
                {
                    child.Command = node.Command;
                }

                foreach (var grandchild in node.Children)
                {
                    child.AddChild(grandchild);
                }
            }
            else
            {
                _children.Add(node.Name, node);
                if (node is LiteralCommandNode <TSource> literalCommandNode)
                {
                    _literals.Add(node.Name, literalCommandNode);
                }
                else if (node is ArgumentCommandNode <TSource> argumentCommandNode)
                {
                    _arguments.Add(node.Name, argumentCommandNode);
                }
            }

            //FIXME: What is the equivalent of this? It looks like this is sorting by entry?
            //       It's probably a performance optimization
            //children = children.entrySet().stream().sorted(Map.Entry.comparingByValue()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e1, LinkedHashMap::new));
        }
Beispiel #7
0
 public LiteralCommandNode(string literal, Command <TSource> command, Predicate <TSource> requirement, CommandNode <TSource> redirect, RedirectModifier <TSource> modifier, bool forks)
     : base(command, requirement, redirect, modifier, forks)
 {
     Literal = literal;
 }
Beispiel #8
0
 /// <summary>
 /// Provide collection initialization, same as calling AddChild
 /// </summary>
 /// <param name="node">Command nodes to add</param>
 public void Add(CommandNode <TSource> node)
 {
     AddChild(node);
 }
 private bool EqualsInternal(CommandNode <TSource> other)
 {
     return(Equals(Children, other.Children) && Equals(Command, other.Command));
 }
Beispiel #10
0
 protected ArgumentCommandNode(Command <TSource> command, Predicate <TSource> requirement, CommandNode <TSource> redirect, RedirectModifier <TSource> modifier, bool forks)
     : base(command, requirement, redirect, modifier, forks)
 {
 }