private static bool CommandModeFilter(CommandExecutionMode executionMode, BaseCommandConfig baseCommandConfig)
        {
            if (executionMode == CommandExecutionMode.CommandLine)
                return baseCommandConfig.ValidInNonInteractiveContext;

            if (executionMode == CommandExecutionMode.Interactive)
                return baseCommandConfig.ValidInInteractiveContext;

            return false;
        }
 public ParserResult(BaseCommandConfig command, string name)
 {
     _positionals = command.Positionals.ToList();
     _usedPositionals = new List<string>();
     _options = command.Options
         .SelectMany(o => new[] { OptionCollectionEntry(o) }.Concat(OptionAliases(o)))
         .ToDictionary(c => c.Key, c => c.Value);
     _usedOptions = new List<BaseOption>();
     ParamObject = command.Create(name);
     Status = ParseStatus.Incomplete;
 }
        private static IConsoleRenderer FormatFullCommandDescription(BaseCommandConfig command, string prefixText = null, IOptionNameHelpAdorner adorner = null, bool displayCommandName = true)
        {
            var formatter = new RecordingConsoleAdapter();
            formatter.WrapLine(((IContext)command).Description ?? string.Empty);

            var positionalsPresent = command.Positionals.Any();
            var optionsPresent = command.Options.Any();
            if (positionalsPresent || optionsPresent)
            {
                formatter.WriteLine();

                var paramList = !positionalsPresent ? String.Empty :
                    " " + command.Positionals.Select(FormatParameterListEntry)
                        .Aggregate((t, i) => t + " " + i);
                var options = !optionsPresent ? String.Empty : " [options]";
                formatter.WrapLine(string.Format("{0}{1}{2}{3}", prefixText ?? String.Empty, displayCommandName ? command.Name : null, paramList, options));
            }

            if (positionalsPresent)
            {
                formatter.WriteLine();
                formatter.WriteLine("Parameters:");
                formatter.WriteLine();
                var positionals = command.Positionals
                    .Select(p => new {p.ParameterName, Description = FormatPositionalDescription(p)});
                formatter.FormatTable(positionals, FormattingOptions, ColumnSeperator);
            }

            if (optionsPresent)
            {
                formatter.WriteLine();
                formatter.WriteLine("Options:");
                formatter.WriteLine();

                var options = command.Options
                    .Select(o => new { OptionName = GetOptionNameAndAliases(adorner, o), o.Description });
                formatter.FormatTable(options, FormattingOptions, ColumnSeperator);
            }

            return formatter;
        }
 public void SetUp()
 {
     _config = new CommandLineInterpreterConfiguration();
     _command = _config.Parameters(() => new CommandParams())
         .Positional<string>("pos1", (c, s) => c.Pos1 = s)
         .Positional<int>("pos2", (c, i) => c.Pos2 = i)
         .Option<string, int>("opt1", (c, s, i) =>
         {
             c.Opt1String = s;
             c.Opt1Int = i;
         })
             .Alias("1")
             .Alias("one")
         .Option("opt2", (c, b) => c.Opt2 = b)
             .Alias("2")
             .Alias("two")
         .Option<string>("opt3", (c, s) => c.Opt3 = s)
             .Alias("3")
             .Alias("three");
     _parserResult = new ParserResult(_command, "commandName");
 }
 private static void AddDefaultCommandText(IConsoleAdapter console, BaseCommandConfig defaultCommand, string applicationName, IOptionNameHelpAdorner adorner)
 {
     console.Write(FormatFullCommandDescription(defaultCommand, string.Format("Usage: {0}", applicationName), adorner, false));
 }
 public static void Describe(BaseCommandConfig command, IConsoleAdapter console, CommandExecutionMode executionMode, IOptionNameHelpAdorner adorner)
 {
     console.Write(FormatFullCommandDescription(command, adorner: adorner));
 }
 private static string FormatShortCommandDescription(BaseCommandConfig command, string prefixText = null)
 {
     return ((IContext)command).Description ?? string.Empty;
 }
 /// <summary>
 /// Get the full list of ways each option can be referenced. i.e. by its actual name, and all of its aliases.
 /// </summary>
 /// <param name="command">The command.</param>
 /// <returns>A list of IOption implementations.</returns>
 private IEnumerable<IOption> GetOptionsAndAliases(BaseCommandConfig command)
 {
     return command
         .Options
         .SelectMany(o => new IOption[] {o}
                             .Concat(o.Aliases.Select(a => new OptionAlias(o, a))));
 }