/// <summary>
        /// Initailizes
        /// </summary>
        /// <param name="name">Name of the arg</param>
        /// <param name="desc">Description of the arg</param>
        /// <param name="alias">Alias for the arg</param>
        /// <param name="type">Datatype of the arg</param>
        /// <param name="required">Whether or not arg is required</param>
        /// <param name="defaultVal">Default value of arg</param>
        /// <param name="examples">Examples of arg</param>
        public void AddArg(string name, string type, bool required, string alias, object defaultVal, string examples, string desc)
        {
            var arg = new ArgAttribute();

            arg.Name         = name;
            arg.Desc         = desc;
            arg.Type         = type;
            arg.Required     = required;
            arg.DefaultValue = defaultVal;
            arg.Alias        = alias;
            arg.Examples     = new List <string>()
            {
                examples
            };
            arg.Index = this.Arguments.Count;
            this.Arguments.Add(arg);
            this.ArgumentsLookup[arg.Name]  = arg;
            this.ArgumentsLookup[arg.Alias] = arg;
            this.ArgumentNames[arg.Name]    = arg.Name;
            this.ArgumentNames[arg.Alias]   = arg.Name;
        }
        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="name"></param>
        /// <param name="argNames"></param>
        public void Init(string name, List <string> argNames)
        {
            this.Name            = name;
            this.Arguments       = new List <ArgAttribute>();
            this.ArgumentNames   = new Dictionary <string, string>();
            this.ArgumentsLookup = new Dictionary <string, ArgAttribute>();

            if (argNames != null && argNames.Count > 0)
            {
                for (int ndx = 0; ndx < argNames.Count; ndx++)
                {
                    var argName = argNames[ndx];
                    var arg     = new ArgAttribute()
                    {
                        Name = argName
                    };
                    arg.Index = ndx;
                    this.Arguments.Add(arg);
                    this.ArgumentsLookup[argName] = arg;
                    this.ArgumentNames[argName]   = argName;
                }
            }
        }
Example #3
0
 private static void ParseExamples(ArgAttribute arg, string example)
 {
     if (!example.Contains("|"))
         arg.Examples.Add(example);
     else
     {
         string[] examples = example.Split('|');
         foreach (var ex in examples)
             arg.Examples.Add(ex.Trim());
     }
 }
Example #4
0
        /// <summary>
        /// Parses arguments by 
        /// </summary>
        /// <param name="argText"></param>
        /// <returns></returns>
        private static ArgAttribute ParseArgByPositionProperties(string argText)
        {
            var arg = new ArgAttribute();
            // NOTE: Do a simple split on "," for the 1st version of fluentscript.
            string[] fields = argText.Split(',');
            int totalFields = fields.Length;

            // Get the name.
            if (totalFields >= 1) arg.Name = fields[0].Trim();
            if (totalFields >= 2) arg.Desc = fields[1].Trim();
            if (totalFields >= 3) arg.Type = fields[2].Trim();
            if (totalFields >= 4) arg.Alias = fields[3].Trim();

            if (totalFields >= 5)
            {
                var example = fields[4];
                ParseExamples(arg, example);
            }
            return arg;
        }
Example #5
0
        /// <summary>
        /// Parses arguments by 
        /// </summary>
        /// <param name="argText"></param>
        /// <returns></returns>
        private static ArgAttribute ParseArgByNamedProperties(string argText)
        {
            // Remove the @arg: from the argText
            var arg = new ArgAttribute();
            // NOTE: Do a simple split on "," for the 1st version of fluentscript.
            string[] fields = argText.Split(',');
            int totalFields = fields.Length;
            foreach (var field in fields)
            {
                var tokens = field.Split(':');

                // Name
                string name = tokens[0].Trim().ToLower();
                string value = tokens[1].Trim();
                if (name == "name") arg.Name = value;
                else if (name == "desc") arg.Desc = value;
                else if (name == "alias") arg.Alias = value;
                else if (name == "type") arg.Type = value;
                else if (name == "examples")
                {
                    ParseExamples(arg, value);
                }
            }
            return arg;
        }
Example #6
0
        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="name"></param>
        /// <param name="argNames"></param>
        public void Init(string name, List<string> argNames)
        {
            this.Name = name;
            this.Arguments = new List<ArgAttribute>();
            this.ArgumentNames = new Dictionary<string, string>();
            this.ArgumentsLookup = new Dictionary<string, ArgAttribute>();

            if (argNames != null && argNames.Count > 0)
            {
                for(int ndx = 0; ndx < argNames.Count; ndx++)
                {
                    var argName = argNames[ndx];
                    var arg = new ArgAttribute() { Name = argName };
                    arg.Index = ndx;
                    this.Arguments.Add(arg);
                    this.ArgumentsLookup[argName] = arg;
                    this.ArgumentNames[argName] = argName;
                }
            }
        }
Example #7
0
 /// <summary>
 /// Initailizes
 /// </summary>
 /// <param name="name">Name of the arg</param>
 /// <param name="desc">Description of the arg</param>
 /// <param name="alias">Alias for the arg</param>
 /// <param name="type">Datatype of the arg</param>
 /// <param name="required">Whether or not arg is required</param>
 /// <param name="defaultVal">Default value of arg</param>
 /// <param name="examples">Examples of arg</param>
 public void AddArg(string name, string type, bool required, string alias, object defaultVal, string examples, string desc)
 {
     var arg = new ArgAttribute();
     arg.Name = name;
     arg.Desc = desc;
     arg.Type = type;
     arg.Required = required;
     arg.DefaultValue = defaultVal;
     arg.Alias = alias;
     arg.Examples = new List<string>() { examples };
     arg.Index = this.Arguments.Count;
     this.Arguments.Add(arg);
     this.ArgumentsLookup[arg.Name] = arg;
     this.ArgumentsLookup[arg.Alias] = arg;
     this.ArgumentNames[arg.Name] = arg.Name;
     this.ArgumentNames[arg.Alias] = arg.Name;
 }
Example #8
0
 /// <summary>
 /// Converts the parameter value into the proper type of the argument.
 /// </summary>
 /// <param name="arg"></param>
 /// <param name="param"></param>
 /// <returns></returns>
 private object ConvertToProperType(ArgAttribute arg, object param)
 {
     object val = param;
     if (param is LObject)
     {
         var lobj = (LObject)param;
         var isInt = arg.Type == "int" && lobj.Type == LTypes.Number;
         val = isInt ? Convert.ToInt32(lobj.GetValue()) : lobj.GetValue();
     }
     return val;
 }