Ejemplo n.º 1
0
        public static T Read <T>(string[] args, IDictionary <string, object> config) where T : IOptionBag, new()
        {
            var options = Parse(args, config);
            var bag     = ProcessOptionBag <T>(options);

            if (options.Count > 0)
            {
                var arr = new DyObject[options.Count];
                var cc  = 0;

                foreach (var kv in options)
                {
                    arr[cc++] = new DyLabel(kv.Key.TrimStart('-'), kv.Value.ToObject());

                    if (kv.Key[0] != '-')
                    {
                        throw new DyaException($"Unknown switch -{kv.Key}.");
                    }
                }

                bag.UserArguments = new DyTuple(arr);
            }

            return(bag);
        }
Ejemplo n.º 2
0
        private static DyObject[] GetArray(List <DNode> nodes, bool allowLabels)
        {
            var arr = new DyObject[nodes.Count];

            for (var i = 0; i < nodes.Count; i++)
            {
                var      e = nodes[i];
                DyObject obj;

                if (allowLabels && e.NodeType == NodeType.Label)
                {
                    var lab = (DLabelLiteral)e;
                    obj = new DyLabel(lab.Label, Eval(lab.Expression));
                }
                else
                {
                    obj = Eval(e);
                }

                arr[i] = obj;
            }

            return(arr);
        }