예제 #1
0
        /// <summary>
        /// Generates an invocation for the current command.
        /// </summary>
        /// <param name="tokens"></param>
        /// <returns></returns>
        /// <remarks>Useful in testing your command structure.</remarks>
        private Action GetAction(params string[] tokens)
        {
            var token      = tokens.FirstOrDefault();
            var subCommand = SubCommands.FirstOrDefault(cmd => cmd.IsIdentifiedBy(token));

            if (subCommand == null)
            {
                return(GetAction(tokens, token));
            }

            var theRest = tokens.Skip(1).ToArray();
            var action  = subCommand.GetAction(theRest);

            return(action ?? GetAction(tokens, token));
        }
예제 #2
0
 public Command FindSubCommand(string name)
 => SubCommands.FirstOrDefault(sc => sc.Name == name.ToLowerInvariant() ||
                               sc.Aliases.Contains(name.ToLowerInvariant()));
예제 #3
0
 internal Command GetSubCommandByToken(string token)
 {
     return(SubCommands.FirstOrDefault(cmd => cmd.IsIdentifiedBy(token)));
 }