Ejemplo n.º 1
0
        static bool NeedAssignment(CommandLineManagerAttribute managerAttribute, CommandLineOptionGroupAttribute groupAttribute, CommandLineOptionAttribute optionAttriubte)
        {
            if (optionAttriubte.RequireExplicitAssignmentAssigned)
            {
                return(optionAttriubte.RequireExplicitAssignment);
            }
            else if (groupAttribute != null && groupAttribute.RequireExplicitAssignmentAssigned)
            {
                return(groupAttribute.RequireExplicitAssignment);
            }
            else if (managerAttribute != null && managerAttribute.RequireExplicitAssignmentAssigned)
            {
                return(managerAttribute.RequireExplicitAssignment);
            }

            return(false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets a string describing all the options of this option manager. Usable for displaying as a help
        /// message to the user, provided that descriptions for all options and groups are provided.
        /// </summary>
        /// <returns>A string describing all the options of this option manager.</returns>
        public string GetOptionsAsString()
        {
            StringBuilder builder = new StringBuilder();

            if (parser.OptionAttributes.Length > 0)
            {
                builder.AppendLine(CommandLineGui.Properties.Resources.Options);
                var optionAttributesGrouped = parser.OptionAttributes.GroupBy(d => d.GroupId).OrderBy(k => k.Key);

                foreach (var optionsInGroup in optionAttributesGrouped)
                {
                    var groupId = optionsInGroup.Key;
                    if (!String.IsNullOrEmpty(groupId))
                    {
                        CommandLineOptionGroupAttribute groupAttribute = null;
                        parser.GroupAttributesDic.TryGetValue(groupId, out groupAttribute);

                        string groupName = groupAttribute == null ? null : groupAttribute.Name;
                        if (groupName != null)
                        {
                            builder.AppendLine(groupName + ":");
                        }
                    }

                    foreach (var option in optionsInGroup)
                    {
                        StringBuilder bb = new StringBuilder();
                        string        s  = parser.CommandLineManagerAttribute.OptionSeparator;
                        bb.Append(s + option.Name);
                        if (option.AliasesArray != null)
                        {
                            bb.Append(", ");
                            var aliasesWithSeparator = option.AliasesArray.Select(d => s + d).ToArray();
                            bb.Append(String.Join(", ", aliasesWithSeparator));
                        }

                        builder.Append(CreateColumnsText(3, 20, bb.ToString(), option.Description));
                    }
                }
            }

            return(builder.ToString());
        }