Example #1
0
        private ParsingResult ValidateSwitchValue(SwitchDescriptor S, string Value)
        {
            var Result = new ParsingResult();

            if (S.SwitchValueType != SwitchValueTypeEnum._none)
            {
                if (string.IsNullOrEmpty(Value))
                {
                    return(WithResult(Result, $"argument of --{S.SwitchText} cannot be empty"));
                }
                else
                {
                    switch (S.SwitchValueType)
                    {
                    case SwitchValueTypeEnum._long:
                        if (!long.TryParse(Value, out long intResult))
                        {
                            return(WithResult(Result, $"argument of --{S.SwitchText} is not a valid long"));
                        }
                        else
                        {
                            return(WithSuccess());
                        }

                    case SwitchValueTypeEnum._bool:
                        if (!bool.TryParse(Value, out bool boolResult))
                        {
                            return(WithResult(Result, $"argument of --{S.SwitchText} is not a valid bool"));
                        }
                        else
                        {
                            return(WithSuccess());
                        }

                    case SwitchValueTypeEnum._string:
                        return(WithSuccess());

                    case SwitchValueTypeEnum._list:
                        if (S.PossibleValues.Where(f => f.Equals(Value, StringComparison.InvariantCultureIgnoreCase)).Count() == 0)
                        {
                            return(WithResult(Result, $"argument of --{S.SwitchText} does not correspond to an entry from the list of possible values"));
                        }
                        else
                        {
                            return(WithSuccess());
                        }
                    }
                }

                return(WithResult(Result, $"argument of --{S.SwitchText} is using an invalid {nameof(SwitchValueTypeEnum)}"));
            }
            else
            {
                return(WithSuccess());
            }
        }
Example #2
0
        private bool TestSwitch(SwitchDescriptor S, string Value)
        {
            if ((SwitchTextSeperator + S.SwitchText).Equals(Value, StringComparison.InvariantCultureIgnoreCase))
            {
                return(true);
            }

            if (!string.IsNullOrWhiteSpace(S.ShortSwitch))
            {
                if ((ShortSwitchSeperator + S.ShortSwitch).Equals(Value, StringComparison.InvariantCultureIgnoreCase))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #3
0
        private void PrintSwitch(int TabCount, SwitchDescriptor Switch)
        {
            string SwText = SwitchTextSeperator + Switch.SwitchText;

            if (!string.IsNullOrEmpty(Switch.ShortSwitch))
            {
                SwText += ", " + ShortSwitchSeperator + Switch.ShortSwitch;
            }

            Con1.PrintText(L(TabCount, SwText), true);

            if (Switch.SwitchValueType != SwitchValueTypeEnum._none)
            {
                Con1.PrintText(":");
                switch (Switch.SwitchValueType)
                {
                case SwitchValueTypeEnum._long:
                    Con1.PrintText("{LONG}");
                    break;

                case SwitchValueTypeEnum._bool:
                    Con1.PrintText("{BOOL}");
                    break;

                case SwitchValueTypeEnum._string:
                    Con1.PrintText("{STRING}");
                    break;

                case SwitchValueTypeEnum._list:
                    Con1.PrintText("{");
                    if (Switch.PossibleValues?.Length > 0)
                    {
                        foreach (var item in Switch.PossibleValues)
                        {
                            Con1.PrintText(item + ",");
                        }
                    }
                    else
                    {
                        Con1.PrintText("..,n");
                    }

                    Con1.PrintText("}");
                    break;
                }
            }

            if (Switch.Required)
            {
                Con1.PrintText(" (required)", true);
            }

            Con1.LF();
            Con1.PrintText(L(TabCount + 1, Switch.Description));
            Con1.LF();

            if (Switch.SwitchArguments?.Length > 0)
            {
                int T = TabCount + 1;
                foreach (var item in Switch.SwitchArguments)
                {
                    Con1.PrintText(L(T, "{" + item.Argument + "}"), true);
                    Con1.LF();
                    Con1.PrintText(L(T + 1, item.Description));
                    Con1.LF();
                }
            }
        }