Beispiel #1
0
        protected internal Option(
            string[] aliases,
            string help,
            ArgumentsRule arguments = null,
            Option[] options        = null)
        {
            if (aliases == null)
            {
                throw new ArgumentNullException(nameof(aliases));
            }

            if (!aliases.Any())
            {
                throw new ArgumentException("An option must have at least one alias.");
            }

            if (aliases.Any(string.IsNullOrWhiteSpace))
            {
                throw new ArgumentException("An option alias cannot be null, empty, or consist entirely of whitespace.");
            }

            RawAliases = aliases;

            foreach (var alias in aliases)
            {
                this.aliases.Add(alias.RemovePrefix());
            }

            HelpText = help;

            Name = aliases
                   .Select(a => a.RemovePrefix())
                   .OrderBy(a => a.Length)
                   .Last();

            if (options != null && options.Any())
            {
                foreach (var option in options)
                {
                    option.Parent = this;
                    DefinedOptions.Add(option);
                }
            }

            ArgumentsRule = arguments ?? Accept.NoArguments();

            if (options != null)
            {
                ArgumentsRule = ArgumentsRule.And(Accept.ZeroOrMoreOf(options));
            }

            AllowedValues = ArgumentsRule.AllowedValues;

            suggest = ArgumentsRule.Suggest;
        }
Beispiel #2
0
 public static Command RootCommand(params Option[] options) =>
 Command(executableName.Value, "", Accept.NoArguments(), options);