예제 #1
0
        public CommandAction Select(string actionName, Command command, IEnumerable<CommandAction> availableActions)
        {
            CommandAction action = new MatchSelector<CommandAction>().Match(actionName, availableActions, c => c.Name);

            if (action != null)
                return action;

            var exception = new CommandActionNotFoundException(actionName, command);
            exception.AvailableActions.AddRange(availableActions);

            var possibleActions = new MatchSelector<CommandAction>().PartialMatch(actionName, availableActions, c => c.Name);
            exception.PossibleActions.AddRange(possibleActions);

            throw exception;
        }
예제 #2
0
        public void ShowCommandHelp(Command command, List<CommandAction> availableActions)
        {
            var maximumActionNameLength = availableActions.Count() > 0 ? availableActions.Max(c => c.Name.Length) : 0;

            var actionTable =
                new ConsoleTable().AddRow(
                    new ConsoleCell(String.Format("The available actions for command '{0}' are:", command.Name)).WithPadding(0));

            int maximumPrototypeLength = 0;

            foreach (var action in availableActions)
            {
                if (action.Parameters.Count > 0)
                {
                    var prototypeLength = action.Parameters
                        .Max(c => c.GetOptionPrototypeHelp().Length);

                    if (prototypeLength > maximumPrototypeLength)
                        maximumPrototypeLength = prototypeLength;
                }
            }

            foreach (var action in availableActions)
            {
                actionTable.AddRow(
                    new ConsoleCell(action.Name).WithWidth(maximumActionNameLength),
                    new ConsoleCell(action.Description));

                if (action.Parameters.Count > 0)
                {
                    foreach (var p in action.Parameters)
                    {
                        actionTable.AddRow(new ConsoleCell(p.GetOptionPrototypeHelp()).
                                               WithWidth(maximumPrototypeLength).WithPadding(6),
                                           new ConsoleCell(p.Description));
                    }
                }

                if (availableActions.Last() != action)
                    actionTable.AddEmptyRow();
            }

            new ConsoleFormatter(ConsoleWriter.Default).Write(actionTable);
        }
예제 #3
0
 public IEnumerable<CommandAction> FindInCommand(Command command)
 {
     return FindInType(command.LinkedToType);
 }