private static HelpPage GetCommandHelp(ArgumentSyntax argumentSyntax, ArgumentCommand command)
 {
     return(new HelpPage
     {
         ApplicationName = argumentSyntax.ApplicationName,
         SyntaxElements = GetCommandSyntax(argumentSyntax, command),
         Rows = GetArgumentRows(argumentSyntax, command).ToArray()
     });
 }
Exemple #2
0
        internal Argument(ArgumentCommand command, IEnumerable <string> names, bool isOption, bool isRequired)
        {
            var nameArray = names.ToArray();

            Command    = command;
            Name       = nameArray.First();
            Names      = new ReadOnlyCollection <string>(nameArray);
            IsOption   = isOption;
            IsRequired = isRequired;
        }
Exemple #3
0
        public ArgumentCommand <T> DefineCommand <T>(string name, T value)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException(Strings.NameMissing, "name");
            }

            if (!IsValidName(name))
            {
                var message = string.Format(Strings.CommandNameIsNotValidFmt, name);
                throw new ArgumentException(message, "name");
            }

            if (_commands.Any(c => string.Equals(c.Name, name, StringComparison.Ordinal)))
            {
                var message = string.Format(Strings.CommandAlreadyDefinedFmt, name);
                throw new InvalidOperationException(message);
            }

            if (_options.Concat(_parameters).Any(c => c.Command == null))
            {
                throw new InvalidOperationException(Strings.CannotDefineCommandsIfArgumentsExist);
            }

            var definedCommand = new ArgumentCommand <T>(name, value);

            _commands.Add(definedCommand);
            _definedCommand = definedCommand;

            if (_activeCommand != null)
            {
                return(definedCommand);
            }

            if (!Parser.TryParseCommand(name))
            {
                return(definedCommand);
            }

            _activeCommand = _definedCommand;
            _activeCommand.MarkActive();

            return(definedCommand);
        }
 private static IEnumerable <HelpRow> GetArgumentRows(ArgumentSyntax argumentSyntax, ArgumentCommand command)
 {
     return(argumentSyntax.GetArguments(command)
            .Where(a => !a.IsHidden)
            .Select(a => new HelpRow {
         Header = GetArgumentRowHeader(a), Text = a.Help
     }));
 }
        private static IEnumerable <string> GetCommandSyntax(ArgumentSyntax argumentSyntax, ArgumentCommand command)
        {
            if (command != null)
            {
                yield return(command.Name);
            }

            foreach (var option in argumentSyntax.GetOptions(command).Where(o => !o.IsHidden))
            {
                yield return(GetOptionSyntax(option));
            }

            if (argumentSyntax.GetParameters(command).All(p => p.IsHidden))
            {
                yield break;
            }

            if (argumentSyntax.GetOptions(command).Any(o => !o.IsHidden))
            {
                yield return(@"[--]");
            }

            foreach (var parameter in argumentSyntax.GetParameters(command).Where(o => !o.IsHidden))
            {
                yield return(GetParameterSyntax(parameter));
            }
        }
Exemple #6
0
 internal ArgumentList(ArgumentCommand command, IEnumerable <string> names, IReadOnlyList <T> defaultValue, bool isRequired)
     : base(command, names, true, isRequired)
 {
     Value        = defaultValue;
     DefaultValue = defaultValue;
 }
Exemple #7
0
 internal ArgumentList(ArgumentCommand command, string name, IReadOnlyList <T> defaultValue)
     : base(command, new[] { name }, false, true)
 {
     Value        = defaultValue;
     DefaultValue = defaultValue;
 }
 internal Argument(ArgumentCommand command, IEnumerable <string> names, T defaultValue, bool isRequired)
     : base(command, names, true, isRequired)
 {
     Value = defaultValue;
     Value = DefaultValue = defaultValue;
 }
 internal Argument(ArgumentCommand command, string name, T defaultValue)
     : base(command, new[] { name }, false, true)
 {
     Value        = defaultValue;
     DefaultValue = defaultValue;
 }