예제 #1
0
 protected ActionAP(Argument argument, IActionsContainer container = null)
 {
     Argument      = argument;
     Container     = container;
     OptionStrings = new List <string>(Argument.OptionStrings ?? new string[] { });
     Destination   = Argument.Destination;
     IsRequired    = Argument.IsRequired;
 }
예제 #2
0
 public static void Init(IActionsContainer actionsContainer, ResourceManager resourceManager, SQLiteConnection connection, string tempPath)
 {
     View.ActionContainer = actionsContainer;
     View.ResourceManager = resourceManager;
     View.Connection      = connection;
     View.TempPath        = tempPath;
     if (Directory.Exists(View.TempPath))
     {
         return;
     }
     Directory.CreateDirectory(View.TempPath);
 }
예제 #3
0
        public ArgumentGroup(IActionsContainer container, string title = "", string description = "") : base(container: container)
        {
            Dictionary <string, object> update = new Dictionary <string, object>()
            {
                /*update('conflict_handler', container.conflict_handler)
                *  update('prefix_chars', container.prefix_chars)
                *  update('argument_default', container.argument_default)*/
            };

            // Атрибуты группы
            Title        = title;
            GroupActions = new List <object>();

            // получить большинство атрибутов из контейнера

            /*self._registries = container._registries
             * self._actions = container._actions
             * self._option_string_actions = container._option_string_actions
             * self._defaults = container._defaults
             * self._has_negative_number_optionals = container._has_negative_number_optionals
             * self._mutually_exclusive_groups = container._mutually_exclusive_groups*/
        }
예제 #4
0
 public StoreFalseAction(Argument argument, IActionsContainer container) : base(argument, container)
 {
     Debug.WriteLine(1);
 }
예제 #5
0
 public AppendConstAction(Argument argument, IActionsContainer container) : base(argument, container)
 {
     Debug.WriteLine(1);
 }
예제 #6
0
 public SubParsersAction(Argument argument, IActionsContainer container) : base(argument, container)
 {
     Debug.WriteLine(1);
 }
예제 #7
0
 public VersionAction(Argument argument, IActionsContainer container) : base(argument, container)
 {
     Debug.WriteLine(1);
 }
예제 #8
0
        public ActionsContainer(ParserSettings parserSettings = null, IActionsContainer container = null)
        {
            parserSettings = parserSettings ?? new ParserSettings();

            Description         = parserSettings.Description;
            ArgumentDefault     = parserSettings.ArgumentDefault;
            PrefixChars         = parserSettings.PrefixChars;
            ConflictHandlerType = parserSettings.ConflictHandlerType;

            // Установка реестра для Action"s
            registriesActionFactories = new Dictionary <string, Func <Argument, ActionAP> >();

            // Регистрируем Action"s

            /*Register("action", "none", typeof(StoreAction));
             * Register("action", "store", typeof(StoreAction));
             * Register("action", "store_const", typeof(StoreConstAction));
             * Register("action", "store_true", typeof(StoreTrueAction));
             * Register("action", "store_false", typeof(StoreFalseAction));
             * Register("action", "append", typeof(AppendAction));
             * Register("action", "append_const", typeof(AppendConstAction));
             * Register("action", "count", typeof(CountAction));
             * Register("action", "help", typeof(HelpAction));
             * Register("action", "version", typeof(VersionAction));
             * Register("action", "parsers", typeof(SubParsersAction));*/
            RegisterActions(new Dictionary <string, Func <Argument, ActionAP> >()
            {
                { ActionNames.NONE, arg => new StoreAction(arg, this) },
                { ActionNames.STORE, arg => new StoreAction(arg, this) },
                { ActionNames.STORE_CONST, arg => new StoreConstAction(arg, this) },
                { ActionNames.STORE_TRUE, arg => new StoreTrueAction(arg, this) },
                { ActionNames.STORE_FALSE, arg => new StoreFalseAction(arg, this) },
                { ActionNames.APPEND, arg => new AppendAction(arg, this) },
                { ActionNames.APPEND_CONST, arg => new AppendConstAction(arg, this) },
                { ActionNames.COUNT, arg => new CountAction(arg, this) },
                { ActionNames.HELP, arg => new HelpAction(arg, this) },
                { ActionNames.VERSION, arg => new VersionAction(arg, this) },
                { ActionNames.PARSERS, arg => new SubParsersAction(arg, this) }
            });

            DefaultAction = ActionNames.NONE;
            // регистрируем типы
            AddSimpleTypeFactories(new Dictionary <string, Type>
            {
                { "int", typeof(int) },
                { "uint", typeof(uint) },
                { "float", typeof(float) },
                { "double", typeof(double) },
                { "decimal", typeof(decimal) },
                { "datetime", typeof(DateTime) },
                { "datetimeoffset", typeof(DateTimeOffset) },
                { "timespan", typeof(TimeSpan) },
                { "string", typeof(string) }
            });

            // Вызываем исключение, если не установлен обработчик ошибок
            GetHandler();

            // Хранилище action
            actions             = new List <ActionAP>();
            OptionStringActions = new Dictionary <string, ActionAP>(StringComparer.InvariantCulture);

            // Группы
            ActionGroups            = new List <ArgumentGroup>();
            MutuallyExclusiveGroups = new List <object>();

            // Хранилище по умолчанию
            Defaults = new Dictionary <string, object>(StringComparer.InvariantCulture);

            // определяет, выглядит ли «опция» как отрицательное число
            // self._negative_number_matcher = _re.compile(r'^-\d+$|^-\d*\.\d+$')
            NegativeNumberMatcher = new Regex(@"^-\d+(\.\d*)?$|^-\.\d+$");

            // есть ли какие-либо дополнительные опции, которые выглядят как отрицательные
            // числа - используем список, чтобы его можно было разделять и редактировать
            HasNegativeNumberOptionals = new List <object>();
        }