예제 #1
0
        private string getArgsUsage(ScriptContext context, int width, CommandLineParameters items)
        {
            List<Var> sb = new List<Var>();

            foreach (CommandLineParameter p in items)
            {
                string text = p.GetTransformedValue(context);
                string vardescr = p.GetDescription(context);

                string name;
                bool emptyName = (p.Switch ?? string.Empty).Trim().Length == 0;
                if (emptyName && string.IsNullOrEmpty(p.Var))
                    name = p.Switch ?? string.Empty;
                else
                {

                    if (string.IsNullOrEmpty(text))
                        continue;
                    if (emptyName)
                        name = " ";
                    else
                    {
                        var pp = items.GetSwitchPrefixesArray();
                        name = "  " + ((pp != null && pp.Length > 0) ? pp[0] : string.Empty) + p.Switch;
                    }
                }

                if (p.Count != CommandLineValueCount.None)
                {

                    if (p.Unspecified == null || emptyName)
                    {
                        if (!string.IsNullOrEmpty(vardescr))
                            name += " " + vardescr;
                    }
                    else
                        name += " [" + vardescr + "]";
                }

                StringBuilder vb = new StringBuilder();
                vb.Append(text);
                if ((Options & UsageOptions.AutoSuffix) != 0)
                {
                    if (p.Required)
                        vb.Append(" (required)");
                    else if (p.Default != null && p.Count != CommandLineValueCount.None)
                    {
                        string def = Utils.To<string>(context.Transform(p.Default, p.Transform));
                        vb.Append(" (default: " + def + ")");
                    }

                }
                Var v = new Var(name, vb.ToString());
                sb.Add(v);
            }

            StringWriter sw = new StringWriter();
            Utils.WrapTwoColumns(sw, sb, 30, width);
            return sw.ToString();
        }